Skip to content
Snippets Groups Projects
Verified Commit baa7ad08 authored by Dave Long's avatar Dave Long
Browse files

Issue #3504902 by catch, berdir, kristiaanvandeneynde: Preload cache tags in cache getMultiple

parent e0a4d441
No related branches found
No related tags found
2 merge requests!3478Issue #3337882: Deleted menus are not removed from content type config,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #461430 passed with warnings
Pipeline: drupal

#461440

    Pipeline: drupal

    #461438

      Pipeline: drupal

      #461432

        ......@@ -98,6 +98,18 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
        $result = apcu_fetch(array_keys($map));
        $cache = [];
        if ($result) {
        // Before checking the validity of each item individually, register the
        // cache tags for all returned cache items for preloading, this allows the
        // cache tag service to optimize cache tag lookups.
        if ($this->checksumProvider instanceof CacheTagsChecksumPreloadInterface) {
        $tags_for_preload = [];
        foreach ($result as $item) {
        if ($item->tags) {
        $tags_for_preload[] = explode(' ', $item->tags);
        }
        }
        $this->checksumProvider->registerCacheTagsForPreload(array_merge(...$tags_for_preload));
        }
        foreach ($result as $key => $item) {
        $item = $this->prepareItem($item, $allow_invalid);
        if ($item) {
        ......
        ......@@ -182,7 +182,14 @@ public function reset() {
        * Implements \Drupal\Core\Cache\CacheTagsChecksumPreloadInterface::registerCacheTagsForPreload()
        */
        public function registerCacheTagsForPreload(array $cache_tags): void {
        $this->preloadTags = array_merge($this->preloadTags, $cache_tags);
        if (empty($cache_tags)) {
        return;
        }
        // Don't preload delayed tags that are awaiting invalidation.
        $preloadable_tags = array_diff($cache_tags, $this->delayedTags);
        if ($preloadable_tags) {
        $this->preloadTags = array_merge($this->preloadTags, $preloadable_tags);
        }
        }
        /**
        ......
        ......@@ -128,11 +128,23 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
        // ::select() is a much smaller proportion of the request.
        $result = [];
        try {
        $result = $this->connection->query('SELECT [cid], [data], [created], [expire], [serialized], [tags], [checksum] FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE [cid] IN ( :cids[] ) ORDER BY [cid]', [':cids[]' => array_keys($cid_mapping)]);
        $result = $this->connection->query('SELECT [cid], [data], [created], [expire], [serialized], [tags], [checksum] FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE [cid] IN ( :cids[] ) ORDER BY [cid]', [':cids[]' => array_keys($cid_mapping)])->fetchAll();
        }
        catch (\Exception) {
        // Nothing to do.
        }
        // Before checking the validity of each item individually, register the
        // cache tags for all returned cache items for preloading, this allows the
        // cache tag service to optimize cache tag lookups.
        if ($this->checksumProvider instanceof CacheTagsChecksumPreloadInterface) {
        $tags_for_preload = [];
        foreach ($result as $item) {
        if ($item->tags) {
        $tags_for_preload[] = explode(' ', $item->tags);
        }
        }
        $this->checksumProvider->registerCacheTagsForPreload(array_merge(...$tags_for_preload));
        }
        $cache = [];
        foreach ($result as $item) {
        // Map the cache ID back to the original.
        ......
        ......@@ -62,7 +62,7 @@ public function testFrontPageAuthenticatedWarmCache(): void {
        'CacheSetCount' => 0,
        'CacheDeleteCount' => 0,
        'CacheTagInvalidationCount' => 0,
        'CacheTagLookupQueryCount' => 4,
        'CacheTagLookupQueryCount' => 3,
        'ScriptCount' => 2,
        'ScriptBytes' => 123850,
        'StylesheetCount' => 2,
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment