merged branch gajdaw/issue_4719_appendix (PR #4795)

Commits
-------

d1a142e Issue #4719 - (Redis and Memcached fixes and test)

Discussion
----------

Issue #4719 - (Redis and Memcached fixes and test)

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/gajdaw/symfony.png?branch=issue_4719_appendix)](http://travis-ci.org/gajdaw/symfony)
Fixes the following tickets: 4719
Todo:
License of the code: MIT
Documentation PR: -

The same problem concerns `RedisProfilerStorage` and `BaseMemcacheProfilerStorage`.
Solution is similar.
This commit is contained in:
Fabien Potencier 2012-07-09 09:36:40 +02:00
commit c16de9bc30
3 changed files with 52 additions and 22 deletions

View File

@ -153,7 +153,11 @@ abstract class BaseMemcacheProfilerStorage implements ProfilerStorageInterface
'time' => $profile->getTime(),
);
$profileIndexed = false !== $this->getValue($this->getItemName($profile->getToken()));
if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime)) {
if (!$profileIndexed) {
// Add to index
$indexName = $this->getIndexName();
@ -169,6 +173,9 @@ abstract class BaseMemcacheProfilerStorage implements ProfilerStorageInterface
return $this->appendValue($indexName, $indexRow, $this->lifetime);
}
return true;
}
return false;
}

View File

@ -167,7 +167,11 @@ class RedisProfilerStorage implements ProfilerStorageInterface
'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)) {
if (!$profileIndexed) {
// Add to index
$indexName = $this->getIndexName();
@ -183,6 +187,9 @@ class RedisProfilerStorage implements ProfilerStorageInterface
return $this->appendValue($indexName, $indexRow, $this->lifetime);
}
return true;
}
return false;
}

View File

@ -209,6 +209,22 @@ abstract class AbstractProfilerStorageTest extends \PHPUnit_Framework_TestCase
$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
*/