Skip to content
Extraits de code Groupes Projets
Valider 2e09977d rédigé par mattab's avatar mattab
Parcourir les fichiers

Action cache ids, fix integration tests

parent cc3c0630
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -42,8 +42,8 @@ class Cache ...@@ -42,8 +42,8 @@ class Cache
$ids = self::getIdsFromCache($valueToMatch, $sql); $ids = self::getIdsFromCache($valueToMatch, $sql);
if(is_null($ids)) { if(count($ids) == 0) {
return $ids; return null;
} }
$sql = Common::getSqlStringFieldsArray($ids); $sql = Common::getSqlStringFieldsArray($ids);
...@@ -73,7 +73,7 @@ class Cache ...@@ -73,7 +73,7 @@ class Cache
return $cache->fetch($cacheKey); return $cache->fetch($cacheKey);
} }
$ids = $this->fetchIdsFromDb($valueToMatch, $sql); $ids = $this->fetchActionIdsFromDb($valueToMatch, $sql);
$cache->save($cacheKey, $ids, $this->lifetime); $cache->save($cacheKey, $ids, $this->lifetime);
...@@ -103,7 +103,7 @@ class Cache ...@@ -103,7 +103,7 @@ class Cache
* @return array|null * @return array|null
* @throws \Exception * @throws \Exception
*/ */
private function fetchIdsFromDb($valueToMatch, $sql) private function fetchActionIdsFromDb($valueToMatch, $sql)
{ {
$idActions = \Piwik\Db::fetchAll($sql, $valueToMatch); $idActions = \Piwik\Db::fetchAll($sql, $valueToMatch);
...@@ -112,11 +112,6 @@ class Cache ...@@ -112,11 +112,6 @@ class Cache
$ids[] = $idAction['idaction']; $ids[] = $idAction['idaction'];
} }
if (!empty($ids)) { return $ids;
return $ids;
}
// no action was found for CONTAINS / DOES NOT CONTAIN
return null;
} }
} }
\ No newline at end of file
...@@ -644,7 +644,7 @@ class SegmentTest extends IntegrationTestCase ...@@ -644,7 +644,7 @@ class SegmentTest extends IntegrationTestCase
public function test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withoutCache() public function test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withoutCache()
{ {
$this->disableSubqueryCache(); $this->disableSubqueryCache();
$this->assertCacheIsNotUsed(); $this->assertCacheWasHit($hit = 0);
list($pageUrlFoundInDb, $actionIdFoundInDb) = $this->insertActions(); list($pageUrlFoundInDb, $actionIdFoundInDb) = $this->insertActions();
...@@ -701,11 +701,11 @@ class SegmentTest extends IntegrationTestCase ...@@ -701,11 +701,11 @@ class SegmentTest extends IntegrationTestCase
$cache = new TableLogAction\Cache(); $cache = new TableLogAction\Cache();
$this->assertTrue( empty($cache->enable) ); $this->assertTrue( empty($cache->enable) );
$this->assertCacheIsNotUsed(); $this->assertCacheWasHit($hit = 0);
$this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query)); $this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query));
} }
public function test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheIsEmpty() public function test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheSave()
{ {
$this->enableSubqueryCache(); $this->enableSubqueryCache();
...@@ -778,16 +778,16 @@ class SegmentTest extends IntegrationTestCase ...@@ -778,16 +778,16 @@ class SegmentTest extends IntegrationTestCase
public function test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheisHit() public function test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheisHit()
{ {
$this->enableSubqueryCache(); $this->enableSubqueryCache();
$this->assertCacheIsNotUsed(); $this->assertCacheWasHit($hits = 0);
$this->test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheIsEmpty(); $this->test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheSave();
$this->assertCacheWasUsed($hits = 4); $this->assertCacheWasHit($hits = 0);
$this->test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheIsEmpty(); $this->test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheSave();
$this->assertCacheWasUsed($hits = 4 + 4); $this->assertCacheWasHit($hits = 4);
$this->test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheIsEmpty(); $this->test_getSelectQuery_whenPageUrlDoesNotExist_asBothStatements_OR_AND_withCacheSave();
$this->assertCacheWasUsed($hits = 4 + 4 + 4); $this->assertCacheWasHit($hits = 4 + 4);
} }
public function provideContainerConfig() public function provideContainerConfig()
...@@ -828,14 +828,9 @@ class SegmentTest extends IntegrationTestCase ...@@ -828,14 +828,9 @@ class SegmentTest extends IntegrationTestCase
return array($pageUrlFoundInDb, $actionIdFoundInDb); return array($pageUrlFoundInDb, $actionIdFoundInDb);
} }
private function assertCacheIsNotUsed() private function assertCacheWasHit($expectedHits)
{ {
$this->assertTrue(TableLogAction\Cache::$hits == 0, "expected cache was not used, but cache was hit " . TableLogAction\Cache::$hits . " times"); $this->assertTrue(TableLogAction\Cache::$hits == $expectedHits, "expected cache was hit $expectedHits time(s), but got " . TableLogAction\Cache::$hits . " cache hits instead.");
}
private function assertCacheWasUsed($expectedHits)
{
$this->assertTrue(TableLogAction\Cache::$hits == $expectedHits, "expected cache was used $expectedHits times, but got " . TableLogAction\Cache::$hits . " cache hits instead");
} }
private function disableSubqueryCache() private function disableSubqueryCache()
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter