From f52e97e08a3548424e7975328777a7715d0fe2a5 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 9 Aug 2014 12:36:53 +0200 Subject: [PATCH] Fixed problems with persistent search parser cache --- src/Models/SearchParsers/PostSearchParser.php | 9 ++++++--- src/Models/SearchServices/AbstractSearchService.php | 9 +++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Models/SearchParsers/PostSearchParser.php b/src/Models/SearchParsers/PostSearchParser.php index 652024a2..3a77e3c3 100644 --- a/src/Models/SearchParsers/PostSearchParser.php +++ b/src/Models/SearchParsers/PostSearchParser.php @@ -4,14 +4,17 @@ use \Chibi\Sql as Sql; class PostSearchParser extends AbstractSearchParser { private $tags; - private $showHidden = false; - private $showDisliked = false; - private $randomReset = true; + private $showHidden; + private $showDisliked; + private $randomReset; protected function processSetup(&$tokens) { $config = Core::getConfig(); + $this->showHidden = false; + $this->showDisliked = false; + $this->randomReset = true; $this->tags = []; $crit = Sql\Functors::conjunction(); diff --git a/src/Models/SearchServices/AbstractSearchService.php b/src/Models/SearchServices/AbstractSearchService.php index fc417464..b0fc442f 100644 --- a/src/Models/SearchServices/AbstractSearchService.php +++ b/src/Models/SearchServices/AbstractSearchService.php @@ -3,7 +3,7 @@ use \Chibi\Sql as Sql; abstract class AbstractSearchService { - protected static $parser; + private static $parsers = []; public static function getEntities($searchQuery, $perPage = null, $page = 1) { @@ -42,10 +42,11 @@ abstract class AbstractSearchService public static function getParser() { + $key = get_called_class(); $parserClassName = self::getParserClassName(); - if (self::$parser == null) - self::$parser = new $parserClassName(); - return self::$parser; + if (!isset(self::$parsers[$key])) + self::$parsers[$key] = new $parserClassName(); + return self::$parsers[$key]; } protected static function getModelClassName()