Commit 08ac5b34 authored by Jens Segers's avatar Jens Segers

Check connection logging mode before logging the query

parent 9ac52d23
......@@ -25,7 +25,6 @@ class Collection {
public function __construct(Connection $connection, MongoCollection $collection)
{
$this->connection = $connection;
$this->collection = $collection;
}
......@@ -38,9 +37,20 @@ class Collection {
*/
public function __call($method, $parameters)
{
$query = array();
$start = microtime(true);
$result = call_user_func_array([$this->collection, $method], $parameters);
if ($this->connection->logging())
{
// Once we have run the query we will calculate the time that it took to run and
// then log the query, bindings, and execution time so we will report them on
// the event that the developer needs them. We'll log time in milliseconds.
$time = $this->connection->getElapsedTime($start);
$query = [];
// Build the query string.
// Convert the query paramters to a json string.
foreach ($parameters as $parameter)
{
try
......@@ -53,19 +63,10 @@ class Collection {
}
}
$start = microtime(true);
$result = call_user_func_array(array($this->collection, $method), $parameters);
// Once we have run the query we will calculate the time that it took to run and
// then log the query, bindings, and execution time so we will report them on
// the event that the developer needs them. We'll log time in milliseconds.
$time = $this->connection->getElapsedTime($start);
// Convert the query to a readable string.
$queryString = $this->collection->getName() . '.' . $method . '(' . join(',', $query) . ')';
$this->connection->logQuery($queryString, array(), $time);
$this->connection->logQuery($queryString, [], $time);
}
return $result;
}
......
......@@ -305,10 +305,12 @@ class QueryTest extends TestCase {
$results = User::paginate(2);
$this->assertEquals(2, $results->count());
$this->assertNotNull($results->first()->title);
$this->assertEquals(9, $results->total());
$results = User::paginate(2, array('name', 'age'));
$this->assertEquals(2, $results->count());
$this->assertNull($results->first()->title);
$this->assertEquals(9, $results->total());
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment