Closed leevigraham closed 8 years ago
The following code adds caching and removes all but one call to _explode_segments
:
/**
* Replace the current context in a variable name
*
* @access private
* @param string $name The variable name
* @return string
*/
private function _parse_context($name)
{
$uri = ee()->session->cache('stash', 'uri');
if(!$uri) {
// fetch the *unadulterated* URI of the current page
$ee_uri = new EE_URI;
// documented as a 'private' method, but not actually. Called in CI_Router so unlikely to ever be made private.
$ee_uri->_fetch_uri_string();
$ee_uri->_remove_url_suffix();
$ee_uri->_explode_segments();
// provide a fallback value for index pages
$uri = $ee_uri->uri_string();
ee()->session->set_cache('stash', 'uri', $uri);
}
$uri = empty($uri) ? $this->EE->stash_model->get_index_key() : $uri;
Nice. But, I'd store the value in self::$_cache['uri']
rather then Stash's session cache (where stash vars are stored). Want to make a pr against the dev branch?
:+1: Probably should have updated my PR :smile:
It seems stash creates a new EE_URI object for every
exp:stash:get
tag and then fires a couple of methods.This seems quite expensive. Could the
$uri
be cached?https://github.com/croxton/Stash/blob/dev/system/expressionengine/third_party/stash/mod.stash.php#L4088
Blackfire.io is showing these calls take up 5% of the page render in a stash heavy site I'm working on.