@@ -59,6 +59,8 @@ public function find($id, $columns = array('*'))
59
59
*/
60
60
public function getFresh ($ columns = array ('* ' ))
61
61
{
62
+ $ start = microtime (true );
63
+
62
64
// If no columns have been specified for the select statement, we will set them
63
65
// here to either the passed columns, or the standard default of retrieving
64
66
// all of the columns on the table using the "wildcard" column character.
@@ -138,6 +140,11 @@ public function getFresh($columns = array('*'))
138
140
// Execute aggregation
139
141
$ results = $ this ->collection ->aggregate ($ pipeline );
140
142
143
+ // Log query
144
+ $ this ->connection ->logQuery (
145
+ $ this ->from . '.aggregate( ' . json_encode ($ pipeline ) . ') ' ,
146
+ array (), $ this ->connection ->getElapsedTime ($ start ));
147
+
141
148
// Return results
142
149
return $ results ['result ' ];
143
150
}
@@ -147,7 +154,16 @@ public function getFresh($columns = array('*'))
147
154
{
148
155
// Return distinct results directly
149
156
$ column = isset ($ this ->columns [0 ]) ? $ this ->columns [0 ] : '_id ' ;
150
- return $ this ->collection ->distinct ($ column , $ wheres );
157
+
158
+ // Execute distinct
159
+ $ result = $ this ->collection ->distinct ($ column , $ wheres );
160
+
161
+ // Log query
162
+ $ this ->connection ->logQuery (
163
+ $ this ->from . '.distinct(" ' . $ column . '", ' . json_encode ($ wheres ) . ') ' ,
164
+ array (), $ this ->connection ->getElapsedTime ($ start ));
165
+
166
+ return $ result ;
151
167
}
152
168
153
169
// Normal query
@@ -167,6 +183,11 @@ public function getFresh($columns = array('*'))
167
183
if ($ this ->offset ) $ cursor ->skip ($ this ->offset );
168
184
if ($ this ->limit ) $ cursor ->limit ($ this ->limit );
169
185
186
+ // Log query
187
+ $ this ->connection ->logQuery (
188
+ $ this ->from . '.find( ' . json_encode ($ wheres ) . ', ' . json_encode ($ columns ) . ') ' ,
189
+ array (), $ this ->connection ->getElapsedTime ($ start ));
190
+
170
191
// Return results as an array with numeric keys
171
192
return iterator_to_array ($ cursor , false );
172
193
}
@@ -275,6 +296,8 @@ public function whereBetween($column, array $values, $boolean = 'and')
275
296
*/
276
297
public function insert (array $ values )
277
298
{
299
+ $ start = microtime (true );
300
+
278
301
// Since every insert gets treated like a batch insert, we will have to detect
279
302
// if the user is inserting a single document or an array of documents.
280
303
$ batch = true ;
@@ -291,7 +314,14 @@ public function insert(array $values)
291
314
if (!$ batch ) $ values = array ($ values );
292
315
293
316
// Batch insert
294
- return $ this ->collection ->batchInsert ($ values );
317
+ $ result = $ this ->collection ->batchInsert ($ values );
318
+
319
+ // Log query
320
+ $ this ->connection ->logQuery (
321
+ $ this ->from . '.batchInsert( ' . json_encode ($ values ) . ') ' ,
322
+ array (), $ this ->connection ->getElapsedTime ($ start ));
323
+
324
+ return $ result ;
295
325
}
296
326
297
327
/**
@@ -303,8 +333,15 @@ public function insert(array $values)
303
333
*/
304
334
public function insertGetId (array $ values , $ sequence = null )
305
335
{
336
+ $ start = microtime (true );
337
+
306
338
$ result = $ this ->collection ->insert ($ values );
307
339
340
+ // Log query
341
+ $ this ->connection ->logQuery (
342
+ $ this ->from . '.insert( ' . json_encode ($ values ) . ') ' ,
343
+ array (), $ this ->connection ->getElapsedTime ($ start ));
344
+
308
345
if (1 == (int ) $ result ['ok ' ])
309
346
{
310
347
if (!$ sequence )
@@ -391,7 +428,15 @@ public function pluck($column)
391
428
*/
392
429
public function delete ($ id = null )
393
430
{
394
- $ result = $ this ->collection ->remove ($ this ->compileWheres ());
431
+ $ start = microtime (true );
432
+
433
+ $ wheres = $ this ->compileWheres ();
434
+ $ result = $ this ->collection ->remove ($ wheres );
435
+
436
+ // Log query
437
+ $ this ->connection ->logQuery (
438
+ $ this ->from . '.remove( ' . json_encode ($ wheres ) . ') ' ,
439
+ array (), $ this ->connection ->getElapsedTime ($ start ));
395
440
396
441
if (1 == (int ) $ result ['ok ' ])
397
442
{
@@ -414,7 +459,7 @@ public function from($collection)
414
459
$ this ->collection = $ this ->connection ->getCollection ($ collection );
415
460
}
416
461
417
- return $ this ;
462
+ return parent :: from ( $ collection ) ;
418
463
}
419
464
420
465
/**
@@ -528,13 +573,21 @@ public function newQuery()
528
573
*/
529
574
protected function performUpdate ($ query , array $ options = array ())
530
575
{
576
+ $ start = microtime (true );
577
+
531
578
// Default options
532
579
$ default = array ('multiple ' => true );
533
580
534
581
// Merge options and override default options
535
582
$ options = array_merge ($ default , $ options );
536
583
537
- $ result = $ this ->collection ->update ($ this ->compileWheres (), $ query , $ options );
584
+ $ wheres = $ this ->compileWheres ();
585
+ $ result = $ this ->collection ->update ($ wheres , $ query , $ options );
586
+
587
+ // Log query
588
+ $ this ->connection ->logQuery (
589
+ $ this ->from . '.update( ' . json_encode ($ wheres ) . ', ' . json_encode ($ query ) . ', ' . json_encode ($ options ) . ') ' ,
590
+ array (), $ this ->connection ->getElapsedTime ($ start ));
538
591
539
592
if (1 == (int ) $ result ['ok ' ])
540
593
{
0 commit comments