Permalink
Browse files

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.
  • Loading branch information...
2 parents 5def751 + d1a142e commit c16de9bc303b1fe2d7c2ca16baa7bacb9fa4be19 @fabpot fabpot committed Jul 9, 2012
@@ -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;
@@ -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;
@@ -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
*/

0 comments on commit c16de9b

Please sign in to comment.