Skip to content

Commit

Permalink
FIX: Use Hierarchy::prepopulateTreeDataCache() in fluent
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Minnee committed Sep 21, 2018
1 parent 9cb863c commit 01b2e3a
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/Extension/FluentVersionedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ class FluentVersionedExtension extends FluentExtension
protected static $idsInLocaleCache = [];

/**
* Used to enable or disable the prepopulation of the locale content cache
* Defaults to true.
*
* @config
* @var array
* @var boolean
*/
private static $prepopulate_locale_object_types = [];
private static $prepopulate_localecontent_cache = true;

protected function augmentDatabaseDontRequire($localisedTable)
{
Expand Down Expand Up @@ -317,12 +320,6 @@ protected function isLocalisedInStage($stage, $locale = null)
}
}

$ownerClass = get_class($this->owner);
$prepopulateClasses = Config::inst()->get(self::class, 'prepopulate_locale_object_types');
if (is_array($prepopulateClasses) && in_array($ownerClass, $prepopulateClasses)) {
self::prepoulateIdsInLocale($locale, $ownerClass);
}

// Get table
$baseTable = $this->owner->baseTable();
$table = $this->getLocalisedTable($baseTable);
Expand Down Expand Up @@ -362,7 +359,31 @@ public function flushCache()
}

/**
* Prepopulate the cache of
* Hook into {@link Hierarchy::prepopulateTreeDataCache}.
*
* @param DataList $recordList The list of records to prepopulate caches for. Null for all records.
* @param array $options A map of hints about what should be cached. "numChildrenMethod" and
* "childrenMethod" are allowed keys.
*/
public function onPrepopulateTreeDataCache(DataList $recordList = null, array $options = [])
{
if (!Config::inst()->get(static::class, 'prepopulate_localecontent_cache')) {
return;
}

// This functionality hasn't been implemented; it's not actually used right now, so assumeYAGNI
if ($recordList) {
user_error(
"FluentVersionedExtension::onPrepopulateTreeDataCache not currently optimised for recordList use",
E_USER_WARNING
);
}

self::prepoulateIdsInLocale(FluentState::singleton()->getLocale(), $this->owner->baseClass());
}

/**
* Prepopulate the cache of IDs in a locale, to optimise batch calls to isLocalisedInStage.
*
* @param string $locale
* @param string $dataObject
Expand Down

0 comments on commit 01b2e3a

Please sign in to comment.