diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php index 077676b..9000e20 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php @@ -18,9 +18,9 @@ class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterf /** * Holds references to each instantiation so they can be terminated. * - * @var array + * @var \Drupal\Core\KeyValueStore\DatabaseStorageExpirable[] */ - protected $storages; + protected $storages = array(); /** * The database connection. @@ -44,16 +44,20 @@ function __construct(Connection $connection) { * {@inheritdoc} */ public function get($collection) { - $storage = new DatabaseStorageExpirable($collection, $this->connection); - $this->storages[] = $storage; - return $storage; + if (!isset($this->storages[$collection])) { + $this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->connection); + } + return $this->storages[$collection]; } /** - * Implements Drupal\Core\DestructableInterface::terminate(). + * {@inheritdoc} */ public function destruct() { - foreach ($this->storages as $storage) { + if (!empty($this->storages)) { + // Each instance does garbage collection for all collections, so we can + // optimize and only have to call the first, avoids multiple DELETE. + $storage = reset($this->storages); $storage->destruct(); } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 25f75c7..f08c9d7 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -713,6 +713,7 @@ function system_schema() { 'primary key' => array('collection', 'name'), 'indexes' => array( 'all' => array('name', 'collection', 'expire'), + 'expire' => array('expire'), ), );