Problem/Motivation

When trying to share a database dump between coworkers we discovered that the full path to the theme is being cached in state at system.active_theme.THEMENAME. The problem is that his data is not correctly updated when rebuilding the cache and causes errors when trying to load the extension since the path to the THEMENAME.theme is wrong.

Also we have a state query on every request to load those themes, while this could also just be cached information, which is faster, especially once you use something else than the database to cache

Proposed resolution

Convert the state entry to use cache. One point of the original issue was that state never changes, but its not worth to care about this, given
that you have a netto runtime safe in case you use cache over state, which is what you should actually optimize for.

Remaining tasks

User interface changes

API changes

Data model changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because sharing databases is hard. The performance improvement side of it though is kinda a task
Issue priority Major, because it improves every HTML page performance wise, potentially
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikey_p’s picture

mikey_p’s picture

Actually looked into this a little more the only place that theme.active_theme.THEME_NAME is even used is in ThemeInitialization::getActiveThemeByName() where it's being used as a straight cache :(

mikey_p’s picture

Status: Active » Needs review
FileSize
496 bytes

Patch to switch this over to use the cache system.

mikey_p’s picture

Actual patch instead of output of `git status`

mikey_p’s picture

mikey_p’s picture

FileSize
4.04 KB

Improved code comments.

mikey_p’s picture

FileSize
4.13 KB

Removed useless use of use statement.

The last submitted patch, 4: 2499943-active-theme-cache-4.patch, failed testing.

The last submitted patch, 6: 2499943-active-theme-cache-6.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: 2499943-active-theme-cache-7.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: 2499943-active-theme-cache-7.patch, failed testing.

Status: Needs work » Needs review
larowlan’s picture

Is there anyway we can test this, to ensure it doesn't sneak back in?

dawehner’s picture

What about also not storing a full path in there?

mikey_p’s picture

It would be awesome to not store the full path, but that's pretty hardwired into how Extension and ExtensionDiscovery work. The module handler gets around this but not storing serialized extensions, but constructing them based on the name of modules stored in the compiled container. This could work for the theme system, but there is quite a bit more calculation that goes into building the theme list, finding base themes, dependencies, engines, screenshot, regions, etc.

This is then awkwardly cached/stored in State again at system.theme.data which is shared with system_list() (which seems to only be used for themes now) and then it's also cached again in default bin with 'system_list' cache.

Ideally we'd refactor this to completely remove the usage of state here, and it may also be possible to remove system_list() as well.

I think this is a good workaround for now to remove one usage of the state system as a cache, and at least make it possible to remove full paths with a cache clear.

dawehner’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Performance

Yeah I did not wanted to discourage the actual change. I think its perfect to do that, but yeah this is something we maybe should also take care of separately.

Marked #2508435: ThemInitialization uses state, should use cache as duplicate as it would have been the same issue updated the issue summary and added a beta evalulation.

This is perfect

catch’s picture

Status: Reviewed & tested by the community » Needs review

On the duplicate issue I was thinking we could put this in cache.bootstrap - it's used every request and there's only one entry per theme, and invalidated very infrequently. So it's a good candidate for the chained fast backend. Patch looks great otherwise.

Berdir’s picture

Berdir’s picture

Also renamed the variable. We don't usually put the bin name in the variable, so renaming to just $cache.

Status: Needs review » Needs work

The last submitted patch, 20: 2499943-active-theme-cache-20.patch, failed testing.

Berdir’s picture

Apparently a random fail in Drupal\simpletest\Tests\SimpleTestBrowserTest...

star-szr’s picture

Status: Needs work » Reviewed & tested by the community

Makes sense, back to RTBC :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Crediting @catch as the creator of the dupe issue.

This issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed d305a8e and pushed to 8.0.x. Thanks!

  • alexpott committed d305a8e on 8.0.x
    Issue #2499943 by mikey_p, Berdir, catch: system.active_theme.THEMENAME...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.