Loading core/lib/Drupal/Core/Cache/MemoryCounterBackendFactory.php 0 → 100644 +24 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Cache; class MemoryCounterBackendFactory implements CacheFactoryInterface { /** * Instantiated memory cache bins. * * @var \Drupal\Core\Cache\MemoryBackend[] */ protected $bins = []; /** * {@inheritdoc} */ public function get($bin) { if (!isset($this->bins[$bin])) { $this->bins[$bin] = new MemoryCounterBackend(); } return $this->bins[$bin]; } } core/modules/migrate/migrate.post_update.php 0 → 100644 +13 −0 Original line number Diff line number Diff line <?php /** * @file * Post update functions for migrate. */ /** * Clear the source count cache. */ function migrate_post_update_clear_migrate_source_count_cache() { // Empty post_update hook. } core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +14 −22 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\migrate\Plugin\migrate\source; use Drupal\Component\Serialization\Json; use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Event\MigrateRollbackEvent; use Drupal\migrate\Event\RollbackAwareInterface; Loading Loading @@ -246,7 +247,9 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->$property = (bool) $configuration[$config_key]; } } $this->cacheKey = !empty($configuration['cache_key']) ? $configuration['cache_key'] : NULL; if ($this->cacheCounts) { $this->cacheKey = $configuration['cache_key'] ?? $plugin_id . '-' . hash('sha256', Json::encode($configuration)); } $this->idMap = $this->migration->getIdMap(); $this->highWaterProperty = !empty($configuration['high_water_property']) ? $configuration['high_water_property'] : FALSE; Loading @@ -265,7 +268,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition * Initializes the iterator with the source data. * * @return \Iterator * Returns an iteratable object of data for this source. * Returns an iterable object of data for this source. */ abstract protected function initializeIterator(); Loading Loading @@ -486,30 +489,19 @@ public function count($refresh = FALSE) { return -1; } if (!isset($this->cacheKey)) { $this->cacheKey = hash('sha256', $this->getPluginId()); } // If a refresh is requested, or we're not caching counts, ask the derived // class to get the count from the source. if ($refresh || !$this->cacheCounts) { $count = $this->doCount(); $this->getCache()->set($this->cacheKey, $count); } else { // Caching is in play, first try to retrieve a cached count. // Return the cached count if we are caching counts and a refresh is not // requested. if ($this->cacheCounts && !$refresh) { $cache_object = $this->getCache()->get($this->cacheKey, 'cache'); if (is_object($cache_object)) { // Success. $count = $cache_object->data; return $cache_object->data; } } else { // No cached count, ask the derived class to count 'em up, and cache // the result. $count = $this->doCount(); // Update the cache if we are caching counts. if ($this->cacheCounts) { $this->getCache()->set($this->cacheKey, $count); } } return $count; } Loading core/modules/migrate/src/Plugin/migrate/source/SqlBase.php +2 −2 Original line number Diff line number Diff line Loading @@ -383,9 +383,9 @@ protected function fetchNextBatch() { abstract public function query(); /** * {@inheritdoc} * Gets the source count using countQuery(). */ public function count($refresh = FALSE) { protected function doCount() { return (int) $this->query()->countQuery()->execute()->fetchField(); } Loading core/modules/migrate/tests/modules/migrate_cache_counts_test/migrate_cache_counts_test.info.yml 0 → 100644 +5 −0 Original line number Diff line number Diff line name: Cacheable Embedded Data Test type: module description: Module containing a cacheable embedded data source. package: Testing version: VERSION Loading
core/lib/Drupal/Core/Cache/MemoryCounterBackendFactory.php 0 → 100644 +24 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Cache; class MemoryCounterBackendFactory implements CacheFactoryInterface { /** * Instantiated memory cache bins. * * @var \Drupal\Core\Cache\MemoryBackend[] */ protected $bins = []; /** * {@inheritdoc} */ public function get($bin) { if (!isset($this->bins[$bin])) { $this->bins[$bin] = new MemoryCounterBackend(); } return $this->bins[$bin]; } }
core/modules/migrate/migrate.post_update.php 0 → 100644 +13 −0 Original line number Diff line number Diff line <?php /** * @file * Post update functions for migrate. */ /** * Clear the source count cache. */ function migrate_post_update_clear_migrate_source_count_cache() { // Empty post_update hook. }
core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +14 −22 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\migrate\Plugin\migrate\source; use Drupal\Component\Serialization\Json; use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Event\MigrateRollbackEvent; use Drupal\migrate\Event\RollbackAwareInterface; Loading Loading @@ -246,7 +247,9 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->$property = (bool) $configuration[$config_key]; } } $this->cacheKey = !empty($configuration['cache_key']) ? $configuration['cache_key'] : NULL; if ($this->cacheCounts) { $this->cacheKey = $configuration['cache_key'] ?? $plugin_id . '-' . hash('sha256', Json::encode($configuration)); } $this->idMap = $this->migration->getIdMap(); $this->highWaterProperty = !empty($configuration['high_water_property']) ? $configuration['high_water_property'] : FALSE; Loading @@ -265,7 +268,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition * Initializes the iterator with the source data. * * @return \Iterator * Returns an iteratable object of data for this source. * Returns an iterable object of data for this source. */ abstract protected function initializeIterator(); Loading Loading @@ -486,30 +489,19 @@ public function count($refresh = FALSE) { return -1; } if (!isset($this->cacheKey)) { $this->cacheKey = hash('sha256', $this->getPluginId()); } // If a refresh is requested, or we're not caching counts, ask the derived // class to get the count from the source. if ($refresh || !$this->cacheCounts) { $count = $this->doCount(); $this->getCache()->set($this->cacheKey, $count); } else { // Caching is in play, first try to retrieve a cached count. // Return the cached count if we are caching counts and a refresh is not // requested. if ($this->cacheCounts && !$refresh) { $cache_object = $this->getCache()->get($this->cacheKey, 'cache'); if (is_object($cache_object)) { // Success. $count = $cache_object->data; return $cache_object->data; } } else { // No cached count, ask the derived class to count 'em up, and cache // the result. $count = $this->doCount(); // Update the cache if we are caching counts. if ($this->cacheCounts) { $this->getCache()->set($this->cacheKey, $count); } } return $count; } Loading
core/modules/migrate/src/Plugin/migrate/source/SqlBase.php +2 −2 Original line number Diff line number Diff line Loading @@ -383,9 +383,9 @@ protected function fetchNextBatch() { abstract public function query(); /** * {@inheritdoc} * Gets the source count using countQuery(). */ public function count($refresh = FALSE) { protected function doCount() { return (int) $this->query()->countQuery()->execute()->fetchField(); } Loading
core/modules/migrate/tests/modules/migrate_cache_counts_test/migrate_cache_counts_test.info.yml 0 → 100644 +5 −0 Original line number Diff line number Diff line name: Cacheable Embedded Data Test type: module description: Module containing a cacheable embedded data source. package: Testing version: VERSION