Problem/Motivation
The AliasPrefixList isn't cached site specifically.
Steps to reproduce
1. Clear cache.
2. Visit a site that has no aliases for paths with node prefix
3. Node aliases on other sites aren't used
Proposed resolution
cache the alias prefixes site specifically.
Issue fork sites-3601366
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
harlor commentedComment #4
harlor commentedI'm actually not sure if that's enough - likely we should also make the static cache site specific
Comment #5
harlor commentedComment #6
harlor commentedComment #8
hydra commentedThanks @harlor — I rebased onto current
1.xand took a closer look at thetwo cache layers, because I think the key-prefixing wasn't quite covering the case you
were unsure about.
The persistent layer is solved by your per-site
getCid()— each site getsits own cache entry, which fixes the reported cold-cache contamination. The trickier part
is the in-request layer:
CacheCollectorloads its in-memory storage only onceper request (guarded by
cacheLoaded), andloadMenuPathRoots()onlyseeds when storage is empty. So when we switch site mid-request (preview, cross-site alias
generation), the switched-to site's path roots never get seeded and
get()just returns
NULL— the aliases silently don't apply.So instead of prefixing the storage keys, I went with a reload-on-switch:
in the right entry even after the active site has changed.
writes to its own entry, then drop and reload the in-memory state for the new site (which
re-seeds its path roots).
That ends up being a bit less code than the key-prefixing version and handles the
switch case correctly. I also added a kernel test that reproduces the original bug:
a root that's unaliased on site A stays resolvable on site B even though A was cached
first, and switching back to A confirms it wasn't polluted in return.
Would be good to get your eyes on the approach since you opened it.
Comment #9
harlor commentedI think this approach will work - but don't we lose the static cache on every site-switch?
Comment #11
harlor commentedI implemented a new approach that uses a factory to use a separate instance of the AliasPrefixList for every class.
Comment #13
harlor commentedI applied The suggested changes and rebased the branch.
Comment #15
harlor commented