You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Setting the cache key itself is a good idea to avoid file_exists checks, but it feels like doing the work twice. Once resolved from the array, you know the file_exists, and it could be cached in a static array instead and avoid cache checks completely.
Proposal
So this is a quicky and dirty proposal, but it gives an idea
public static function chooseTemplate($templates)
{
static $arr = [];
if (is_string($templates) && isset($arr[$templates])) {
return $templates;
}
$resolved = ThemeResourceLoader::inst()->findTemplate($templates, self::get_themes());
$arr[$resolved] = true;
return $resolved;
}
When a file is resolved, it's stored a in a static array. If we ask for this file again, simply return the file path directly without any cache checks.
If the team is interested, i'm happy to work on a PR.
It's by no means a big issue, but it saves 5 cache calls on a typical admin page for example, but it's probably more if you have lots of includes
The text was updated successfully, but these errors were encountered:
side note: file_exists is also cached at php level directly, so maybe it's even simpler to simply return early and use file_exists checks when given a file path ending with .ss
Affected Version
4/5
Description
Another finding from the new cache collector in the debugbar for v5.
When calling an include, it's first resolved based on an array of argument, then as a path. Typically, this happens for LeftAndMain_Menu
This leads to two cache keys being created for the same entry (one when you give an array, one when you pass a file path)
silverstripe-framework/src/View/ThemeResourceLoader.php
Lines 192 to 196 in 158d51a
Setting the cache key itself is a good idea to avoid file_exists checks, but it feels like doing the work twice. Once resolved from the array, you know the file_exists, and it could be cached in a static array instead and avoid cache checks completely.
Proposal
So this is a quicky and dirty proposal, but it gives an idea
When a file is resolved, it's stored a in a static array. If we ask for this file again, simply return the file path directly without any cache checks.
If the team is interested, i'm happy to work on a PR.
It's by no means a big issue, but it saves 5 cache calls on a typical admin page for example, but it's probably more if you have lots of includes
The text was updated successfully, but these errors were encountered: