Skip to content

Commit

Permalink
Issue #4719 - (Redis and Memcached fixes and test)
Browse files Browse the repository at this point in the history
  • Loading branch information
gajdaw committed Jul 9, 2012
1 parent 5def751 commit d1a142e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 26 deletions.
Expand Up @@ -153,20 +153,27 @@ public function write(Profile $profile)
'time' => $profile->getTime(),
);

$profileIndexed = false !== $this->getValue($this->getItemName($profile->getToken()));

if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime)) {
// Add to index
$indexName = $this->getIndexName();

$indexRow = implode("\t", array(
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
$profile->getUrl(),
$profile->getTime(),
$profile->getParentToken(),
))."\n";

return $this->appendValue($indexName, $indexRow, $this->lifetime);

if (!$profileIndexed) {
// Add to index
$indexName = $this->getIndexName();

$indexRow = implode("\t", array(
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
$profile->getUrl(),
$profile->getTime(),
$profile->getParentToken(),
))."\n";

return $this->appendValue($indexName, $indexRow, $this->lifetime);
}

return true;
}

return false;
Expand Down
33 changes: 20 additions & 13 deletions src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php
Expand Up @@ -167,20 +167,27 @@ public function write(Profile $profile)
'time' => $profile->getTime(),
);

$profileIndexed = false !== $this->getValue($this->getItemName($profile->getToken()));

if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime, self::REDIS_SERIALIZER_PHP)) {
// Add to index
$indexName = $this->getIndexName();

$indexRow = implode("\t", array(
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
$profile->getUrl(),
$profile->getTime(),
$profile->getParentToken(),
))."\n";

return $this->appendValue($indexName, $indexRow, $this->lifetime);

if (!$profileIndexed) {
// Add to index
$indexName = $this->getIndexName();

$indexRow = implode("\t", array(
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
$profile->getUrl(),
$profile->getTime(),
$profile->getParentToken(),
))."\n";

return $this->appendValue($indexName, $indexRow, $this->lifetime);
}

return true;
}

return false;
Expand Down
Expand Up @@ -209,6 +209,22 @@ public function testPurge()
$this->assertCount(0, $this->getStorage()->find('127.0.0.1', '', 10, 'GET'), '->purge() removes all items from index');
}

public function testDuplicates()
{
for ($i = 1; $i <= 5; $i++) {
$profile = new Profile('foo' . $i);
$profile->setIp('127.0.0.1');
$profile->setUrl('http://example.net/');
$profile->setMethod('GET');

///three duplicates
$this->getStorage()->write($profile);
$this->getStorage()->write($profile);
$this->getStorage()->write($profile);
}
$this->assertCount(3, $this->getStorage()->find('127.0.0.1', 'http://example.net/', 3, 'GET'), '->find() method returns incorrect number of entries');
}

/**
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
*/
Expand Down

0 comments on commit d1a142e

Please sign in to comment.