From 4152cc3cb10ef60e6a75098c69f7560af1125de9 Mon Sep 17 00:00:00 2001 From: Matthias Isler Date: Wed, 7 Dec 2016 16:54:13 +0100 Subject: [PATCH] bugfixes --- src/Spiritix/LadaCache/QueryHandler.php | 4 +++- src/Spiritix/LadaCache/Tagger.php | 14 ++++++++++---- tests/IntegrationTest.php | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Spiritix/LadaCache/QueryHandler.php b/src/Spiritix/LadaCache/QueryHandler.php index f1bcd56..a4d5f09 100644 --- a/src/Spiritix/LadaCache/QueryHandler.php +++ b/src/Spiritix/LadaCache/QueryHandler.php @@ -115,7 +115,9 @@ public function cacheQuery($queryClosure) // If not, execute the query closure and cache the result if ($result === null) { - $this->cache->set($key, $tagger->getTags(), $queryClosure()); + $result = $queryClosure(); + + $this->cache->set($key, $tagger->getTags(), $result); } $action = ($result === null) ? 'Miss' : 'Hit'; diff --git a/src/Spiritix/LadaCache/Tagger.php b/src/Spiritix/LadaCache/Tagger.php index 50b18c3..a063f59 100644 --- a/src/Spiritix/LadaCache/Tagger.php +++ b/src/Spiritix/LadaCache/Tagger.php @@ -71,8 +71,6 @@ public function __construct(Reflector $reflector) */ public function getTags() { - $tags = []; - // Get affected database and tables, add prefixes $database = $this->prefix($this->reflector->getDatabase(), self::PREFIX_DATABASE); @@ -90,12 +88,20 @@ public function getTags() // Create the table tags with corresponding prefix // Depending on whether the queries are specific or not - $tags[] = $this->getTableTags($tables, $rows); + $tags = $this->getTableTags($tables, $rows); // Then we loop trough all these tags and add a tag for each row // Consisting of the prefixed table and the row with prefix foreach ($tables as $table) { - $tags = array_merge($tags, $this->prefix($rows[$table], $this->prefix(self::PREFIX_ROW, $table))); + + if (!isset($rows[$table])) { + continue; + } + + $tablePrefix = $this->prefix($table, self::PREFIX_TABLE_SPECIFIC); + $rowPrefix = $this->prefix(self::PREFIX_ROW, $tablePrefix); + + $tags = array_merge($tags, $this->prefix($rows[$table], $rowPrefix)); } return $this->prefix($tags, $database); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 8b03d88..03eb9f9 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -59,7 +59,7 @@ public function testUpdate() $this->assertTrue($this->hasQuery($rowBuilder1->getQuery())); $this->assertTrue($this->hasQuery($rowBuilder2->getQuery())); - $car = Car::find(1); + $car = Car::findOrFail(1); $car->name = 'New'; $car->save();