Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Isler committed Dec 7, 2016
1 parent cc6728a commit 4152cc3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Spiritix/LadaCache/QueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 10 additions & 4 deletions src/Spiritix/LadaCache/Tagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 4152cc3

Please sign in to comment.