Use token as identifier to make usage of the automatically created index.

This commit is contained in:
H. Westphal 2011-09-07 20:49:37 +02:00
parent 49e1eee2a1
commit 4cd2dec01d

View File

@ -40,7 +40,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
$cursor = $this->getMongo()->find(array('ip' => $ip, 'url' => $url))->limit($limit); $cursor = $this->getMongo()->find(array('ip' => $ip, 'url' => $url))->limit($limit);
$return = array(); $return = array();
foreach ($cursor as $profile) { foreach ($cursor as $profile) {
$return[] = $profile['token']; $return[] = $profile['_id'];
} }
return $return; return $return;
@ -65,7 +65,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
*/ */
public function read($token) public function read($token)
{ {
$profile = $this->getMongo()->findOne(array('token' => $token)); $profile = $this->getMongo()->findOne(array('_id' => $token));
return $profile !== null ? unserialize($profile['profile']) : null; return $profile !== null ? unserialize($profile['profile']) : null;
} }
@ -80,7 +80,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
public function write(Profile $profile) public function write(Profile $profile)
{ {
return $this->getMongo()->insert(array( return $this->getMongo()->insert(array(
'token' => $profile->getToken(), '_id' => $profile->getToken(),
'ip' => $profile->getIp(), 'ip' => $profile->getIp(),
'url' => $profile->getUrl() === null ? '' : $profile->getUrl(), 'url' => $profile->getUrl() === null ? '' : $profile->getUrl(),
'profile' => serialize($profile) 'profile' => serialize($profile)
@ -99,7 +99,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
list($database, $collection,) = explode('/', substr(parse_url($this->dsn, PHP_URL_PATH), 1)); list($database, $collection,) = explode('/', substr(parse_url($this->dsn, PHP_URL_PATH), 1));
$this->mongo = $mongo->selectCollection($database, $collection); $this->mongo = $mongo->selectCollection($database, $collection);
} }
return $this->mongo; return $this->mongo;
} }
} }