Fixed MongoDB storage missing time range. Fixed UI not searching properly. Removed unnecessary time query.

This commit is contained in:
Florin Patan 2012-12-15 23:37:18 +02:00
parent 3a0ed584df
commit 7f6e99bc4d
8 changed files with 67 additions and 57 deletions

View File

@ -266,14 +266,14 @@ class ProfilerController
$ip = $request->query->get('ip');
$method = $request->query->get('method');
$url = $request->query->get('url');
$start = $request->query->get('start');
$end = $request->query->get('end');
$start = $request->query->get('start', null);
$end = $request->query->get('end', null);
$limit = $request->query->get('limit');
return new Response($this->twig->render('@WebProfiler/Profiler/results.html.twig', array(
'token' => $token,
'profile' => $profile,
'tokens' => $this->profiler->find($ip, $url, $start, $end, $limit, $method),
'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end),
'ip' => $ip,
'method' => $method,
'url' => $url,
@ -298,8 +298,8 @@ class ProfilerController
$ip = preg_replace('/[^:\d\.]/', '', $request->query->get('ip'));
$method = $request->query->get('method');
$url = $request->query->get('url');
$start = $request->query->get('start');
$end = $request->query->get('end');
$start = $request->query->get('start', null);
$end = $request->query->get('end', null);
$limit = $request->query->get('limit');
$token = $request->query->get('token');
@ -317,7 +317,7 @@ class ProfilerController
return new RedirectResponse($this->generator->generate('_profiler', array('token' => $token)));
}
$tokens = $this->profiler->find($ip, $url, $start, $end, $limit, $method);
$tokens = $this->profiler->find($ip, $url, $limit, $method, $start, $end);
return new RedirectResponse($this->generator->generate('_profiler_search_results', array(
'token' => $tokens ? $tokens[0]['token'] : 'empty',

View File

@ -52,14 +52,6 @@ abstract class BaseMemcacheProfilerStorage implements ProfilerStorageInterface
$profileList = explode("\n", $indexContent);
$result = array();
if (null === $start) {
$start = 0;
}
if (null === $end) {
$end = time();
}
foreach ($profileList as $item) {
if ($limit === 0) {
@ -74,7 +66,15 @@ abstract class BaseMemcacheProfilerStorage implements ProfilerStorageInterface
$itemTime = (int)$itemTime;
if ($ip && false === strpos($itemIp, $ip) || $url && false === strpos($itemUrl, $url) || $method && false === strpos($itemMethod, $method) || $start > $itemTime || $end < $itemTime) {
if ($ip && false === strpos($itemIp, $ip) || $url && false === strpos($itemUrl, $url) || $method && false === strpos($itemMethod, $method)) {
continue;
}
if (!empty($start) && $itemTime < $start) {
continue;
}
if (!empty($end) && $itemTime > $end) {
continue;
}

View File

@ -57,14 +57,6 @@ class FileProfilerStorage implements ProfilerStorageInterface
$file = fopen($file, 'r');
fseek($file, 0, SEEK_END);
if (null === $start) {
$start = 0;
}
if (null === $end) {
$end = time();
}
$result = array();
while ($limit > 0) {
@ -82,7 +74,15 @@ class FileProfilerStorage implements ProfilerStorageInterface
$csvTime = (int)$csvTime;
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method) || $start > $csvTime || $end < $csvTime) {
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method)) {
continue;
}
if (!empty($start) && $csvTime < $start) {
continue;
}
if (!empty($end) && $csvTime > $end) {
continue;
}

View File

@ -36,14 +36,6 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
*/
public function find($ip, $url, $limit, $method, $start = null, $end = null)
{
if (null === $start) {
$start = 0;
}
if (null === $end) {
$end = time();
}
$cursor = $this->getMongo()->find($this->buildQuery($ip, $url, $method, $start, $end), array('_id', 'parent', 'ip', 'method', 'url', 'time'))->sort(array('time' => -1))->limit($limit);
$tokens = array();
@ -190,6 +182,18 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
$query['method'] = $method;
}
if (!empty($start) || !empty($end)) {
$query['time'] = array();
}
if (!empty($start)) {
$query['time']['$gte'] = $start;
}
if (!empty($end)) {
$query['time']['$lte'] = $end;
}
return $query;
}

View File

@ -64,11 +64,15 @@ class MysqlProfilerStorage extends PdoProfilerStorage
$args[':method'] = $method;
}
$criteria[] = 'time >= :start';
$args[':start'] = $start;
if (!empty($start)) {
$criteria[] = 'time >= :start';
$args[':start'] = $start;
}
$criteria[] = 'time <= :end';
$args[':end'] = $end;
if (!empty($end)) {
$criteria[] = 'time <= :end';
$args[':end'] = $end;
}
return array($criteria, $args);
}

View File

@ -174,21 +174,19 @@ class Profiler
if (is_integer($start)) {
$start = '@' . $start;
}
} else {
$start = '@0';
$start = new \DateTime($start);
$start = $start->getTimestamp();
}
$start = new \DateTime($start);
$start = $start->getTimestamp();
if ($end != '' && null !== $end) {
if (is_integer($end)) {
$end = '@' . $end;
}
} else {
$end = 'now';
$end = new \DateTime($end);
$end = $end->getTimestamp();
}
$end = new \DateTime($end);
$end = $end->getTimestamp();
return $this->storage->find($ip, $url, $limit, $method, $start, $end);
}

View File

@ -63,14 +63,6 @@ class RedisProfilerStorage implements ProfilerStorageInterface
$profileList = explode("\n", $indexContent);
$result = array();
if (null === $start) {
$start = 0;
}
if (null === $end) {
$end = time();
}
foreach ($profileList as $item) {
if ($limit === 0) {
break;
@ -84,7 +76,15 @@ class RedisProfilerStorage implements ProfilerStorageInterface
$itemTime = (int)$itemTime;
if ($ip && false === strpos($itemIp, $ip) || $url && false === strpos($itemUrl, $url) || $method && false === strpos($itemMethod, $method) || $start > $itemTime || $end < $itemTime) {
if ($ip && false === strpos($itemIp, $ip) || $url && false === strpos($itemUrl, $url) || $method && false === strpos($itemMethod, $method)) {
continue;
}
if (!empty($start) && $itemTime < $start) {
continue;
}
if (!empty($end) && $itemTime > $end) {
continue;
}

View File

@ -117,11 +117,15 @@ class SqliteProfilerStorage extends PdoProfilerStorage
$args[':method'] = $method;
}
$criteria[] = 'time >= :start';
$args[':start'] = $start;
if (!empty($start)) {
$criteria[] = 'time >= :start';
$args[':start'] = $start;
}
$criteria[] = 'time <= :end';
$args[':end'] = $end;
if (!empty($end)) {
$criteria[] = 'time <= :end';
$args[':end'] = $end;
}
return array($criteria, $args);
}