Skip to content

Commit

Permalink
Cache-stampede mitigation, batch processing of inserts/updates and EE…
Browse files Browse the repository at this point in the history
… 2.9 compatibility
  • Loading branch information
croxton committed Jul 14, 2014
1 parent 10198c1 commit 7160677
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 115 deletions.
2 changes: 1 addition & 1 deletion system/expressionengine/third_party/stash/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
if (! defined('STASH_VER'))
{
define('STASH_NAME', 'Stash');
define('STASH_VER', '2.5.3');
define('STASH_VER', '2.5.4');
define('STASH_AUTHOR', 'Mark Croxton');
define('STASH_DOCS', 'http://github.com/croxton/Stash/');
define('STASH_DESC', 'Stash: save text and code snippets for reuse throughout your templates.');
Expand Down
36 changes: 31 additions & 5 deletions system/expressionengine/third_party/stash/ext.stash.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @package Stash
* @author Mark Croxton ([email protected])
* @copyright Copyright (c) 2012 Hallmark Design
* @copyright Copyright (c) 2014 Hallmark Design
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
* @link http://hallmark-design.co.uk
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ private function _add_hook($name)
* @return array
*/
public function template_fetch_template($row)
{
{
// get the latest version of $row
if (isset($this->EE->extensions->last_call) && $this->EE->extensions->last_call)
{
Expand Down Expand Up @@ -292,9 +292,10 @@ public function template_fetch_template($row)
* @param string Parsed template string
* @param bool Whether an embed or not
* @param integer Site ID
* @param bool Has the extension been called by Stash rather than EE?
* @return string Template string
*/
public function template_post_parse($template, $sub, $site_id)
public function template_post_parse($template, $sub, $site_id, $from_stash = FALSE)
{
// play nice with other extensions on this hook
if (isset($this->EE->extensions->last_call) && $this->EE->extensions->last_call)
Expand Down Expand Up @@ -348,10 +349,10 @@ public function template_post_parse($template, $sub, $site_id)
// loop through, prep the Stash instance, call the postponed tag and replace output into the placeholder
foreach($cache as $placeholder => $tag)
{
// make sure there is a placeholder in the template
// it may have been removed by advanced conditional processing
if ( strpos( $template, $placeholder ) !== FALSE)
{
// make sure there is a placeholder in the template
// it may have been removed by advanced conditional processing
$this->EE->TMPL->log_item("Stash: post-processing tag: " . $tag['tagproper'] . " will be replaced into " . LD . $placeholder . RD);

$this->EE->TMPL->tagparams = $tag['tagparams'];
Expand Down Expand Up @@ -410,6 +411,31 @@ public function template_post_parse($template, $sub, $site_id)

// cleanup
unset($cache);

// just before the template is sent to output
if (FALSE == $from_stash)
{
/*
// remove Stash from the extensions array to avoid infinite recursion
$other_ext = array();
foreach($this->EE->extensions->extensions['template_post_parse'] as $priority => $ext)
{
foreach($ext as $class => $config)
{
if ($class != 'Stash_ext')
{
$other_ext[$priority][$class] = $config;
}
}
}
*/

// batch processing of cached variables
$this->EE->TMPL->log_item("Stash: batch processing queued queries");
$this->EE->load->model('stash_model');
$this->EE->stash_model->process_queue();
}
}

return $template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package Stash
* @author Mark Croxton ([email protected])
* @copyright Copyright (c) 2012 Hallmark Design
* @copyright Copyright (c) 2014 Hallmark Design
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
* @link http://hallmark-design.co.uk
*/
Expand Down
2 changes: 1 addition & 1 deletion system/expressionengine/third_party/stash/mcp.stash.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package Stash
* @author Mark Croxton ([email protected])
* @copyright Copyright (c) 2012 Hallmark Design
* @copyright Copyright (c) 2014 Hallmark Design
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
* @link http://hallmark-design.co.uk
*/
Expand Down
Loading

0 comments on commit 7160677

Please sign in to comment.