Skip to content

Commit

Permalink
Remove 'pre parse' code, because it's too hackish.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdenotter committed Sep 14, 2023
1 parent 4067109 commit 3a0a009
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 68 deletions.
2 changes: 0 additions & 2 deletions config/bolt/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ secret: '%env(APP_SECRET)%'
# The expires_after is counted in seconds.
#caching:
# related_options: 3600
# options_preparse: 1800 # Run `bin/console app:pre-parse` to rebuild these
# canonical: 1800
# formatter: 180
# selectoptions: 3600
Expand All @@ -23,7 +22,6 @@ secret: '%env(APP_SECRET)%'

caching:
related_options: ~
options_preparse: ~ # Run `bin/console app:pre-parse` to rebuild these
canonical: ~
formatter: ~
selectoptions: ~
Expand Down
19 changes: 0 additions & 19 deletions src/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,23 +324,4 @@ public static function convertPHPSizeToBytes(string $size): int

return $value;
}

public function writePreParseCache(string $filename, $options): void
{
$this->cache->get($filename, function(ItemInterface $item) use ($options) {
$item->expiresAfter($this->get('general/caching/options_preparse'));
$item->tag('options_preparse');

return $options;
});
}

public function readPreParseCache(string $filename): ?array
{
$options = $this->cache->get($filename, function() {
return null;
});

return $options;
}
}
23 changes: 0 additions & 23 deletions src/Twig/FieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,6 @@ private function selectOptionsContentType(Field $field): Collection

$order = $field->getDefinition()->get('order', '');

// Check if we have it available as pre-parsed values
$options = $this->readOptionsCache($contentTypeSlug, $order, $format, $maxAmount);
if ($options) {
return new Collection($options);
}

$options = [];

// We need to add this as a 'dummy' option for when the user is allowed
Expand All @@ -298,26 +292,9 @@ private function selectOptionsContentType(Field $field): Collection

$options = array_merge($options, $this->selectOptionsHelper($contentTypeSlug, $params, $field, $format));

// Write the pre-parsed options.
$this->writeOptionsCache($contentTypeSlug, $order, $format, $maxAmount, $options);

return new Collection($options);
}

public function writeOptionsCache(string $toContentTypeSlug, string $order, string $format, int $maxAmount, $options)
{
$key = sprintf('options_%s', mb_substr(md5($toContentTypeSlug . $maxAmount . $order . $format), 0, 8));

$this->config->writePreParseCache($key, $options);
}

public function readOptionsCache(string $toContentTypeSlug, string $order, string $format, int $maxAmount): ?array
{
$key = sprintf('options_%s', mb_substr(md5($toContentTypeSlug . $maxAmount . $order . $format), 0, 8));

return $this->config->readPreParseCache($key);
}

/**
* Decorated by `\Bolt\Cache\SelectOptionsCacher`
*/
Expand Down
24 changes: 0 additions & 24 deletions src/Twig/RelatedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,11 @@ public function getRelatedOptions(ContentType $fromContentType, string $toConten
return new Collection($options);
}


// Check if we have it available as pre-parsed values
$options = $this->readOptionsCache($toContentTypeSlug, $order, $format, $maxAmount);
if ($options) {
return new Collection($options);
}

$options = $this->optionsUtility->fetchRelatedOptions($fromContentType, $toContentTypeSlug, $order, $format, $required, $allowEmpty, $maxAmount, $linkToRecord);

// Write the pre-parsed options.
$this->writeRelatedOptionsCache($toContentTypeSlug, $order, $format, $maxAmount, $options);

return new Collection($options);
}

public function writeRelatedOptionsCache(string $toContentTypeSlug, string $order, string $format, int $maxAmount, $options)
{
$key = sprintf('related_%s', mb_substr(md5($toContentTypeSlug . $maxAmount . $order . $format), 0, 8));

$this->config->writePreParseCache($key, $options);
}

public function readOptionsCache(string $toContentTypeSlug, string $order, string $format, int $maxAmount): ?array
{
$key = sprintf('related_%s', mb_substr(md5($toContentTypeSlug . $maxAmount . $order . $format), 0, 8));

return $this->config->readPreParseCache($key);
}

public function getRelatedValues(Content $source, string $contentType): Collection
{
if (! $this->checkforContent($source, 'related_values')) {
Expand Down

0 comments on commit 3a0a009

Please sign in to comment.