Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
08ac5b34
Commit
08ac5b34
authored
Mar 23, 2015
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check connection logging mode before logging the query
parent
9ac52d23
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
23 deletions
+26
-23
Collection.php
src/Jenssegers/Mongodb/Collection.php
+24
-23
QueryTest.php
tests/QueryTest.php
+2
-0
No files found.
src/Jenssegers/Mongodb/Collection.php
View file @
08ac5b34
...
@@ -25,7 +25,6 @@ class Collection {
...
@@ -25,7 +25,6 @@ class Collection {
public
function
__construct
(
Connection
$connection
,
MongoCollection
$collection
)
public
function
__construct
(
Connection
$connection
,
MongoCollection
$collection
)
{
{
$this
->
connection
=
$connection
;
$this
->
connection
=
$connection
;
$this
->
collection
=
$collection
;
$this
->
collection
=
$collection
;
}
}
...
@@ -38,34 +37,36 @@ class Collection {
...
@@ -38,34 +37,36 @@ class Collection {
*/
*/
public
function
__call
(
$method
,
$parameters
)
public
function
__call
(
$method
,
$parameters
)
{
{
$
query
=
array
(
);
$
start
=
microtime
(
true
);
// Build the query string.
$result
=
call_user_func_array
([
$this
->
collection
,
$method
],
$parameters
);
foreach
(
$parameters
as
$parameter
)
{
try
{
$query
[]
=
json_encode
(
$parameter
);
}
catch
(
Exception
$e
)
{
$query
[]
=
'{...}'
;
}
}
$start
=
microtime
(
true
);
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
);
$result
=
call_user_func_array
(
array
(
$this
->
collection
,
$method
),
$parameters
)
;
$query
=
[]
;
// Once we have run the query we will calculate the time that it took to run and
// Convert the query paramters to a json string.
// then log the query, bindings, and execution time so we will report them on
foreach
(
$parameters
as
$parameter
)
// the event that the developer needs them. We'll log time in milliseconds.
{
$time
=
$this
->
connection
->
getElapsedTime
(
$start
);
try
{
$query
[]
=
json_encode
(
$parameter
);
}
catch
(
Exception
$e
)
{
$query
[]
=
'{...}'
;
}
}
// Convert the query to a readable string.
$queryString
=
$this
->
collection
->
getName
()
.
'.'
.
$method
.
'('
.
join
(
','
,
$query
)
.
')'
;
$queryString
=
$this
->
collection
->
getName
()
.
'.'
.
$method
.
'('
.
join
(
','
,
$query
)
.
')'
;
$this
->
connection
->
logQuery
(
$queryString
,
array
(),
$time
);
$this
->
connection
->
logQuery
(
$queryString
,
[],
$time
);
}
return
$result
;
return
$result
;
}
}
...
...
tests/QueryTest.php
View file @
08ac5b34
...
@@ -305,10 +305,12 @@ class QueryTest extends TestCase {
...
@@ -305,10 +305,12 @@ class QueryTest extends TestCase {
$results
=
User
::
paginate
(
2
);
$results
=
User
::
paginate
(
2
);
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertNotNull
(
$results
->
first
()
->
title
);
$this
->
assertNotNull
(
$results
->
first
()
->
title
);
$this
->
assertEquals
(
9
,
$results
->
total
());
$results
=
User
::
paginate
(
2
,
array
(
'name'
,
'age'
));
$results
=
User
::
paginate
(
2
,
array
(
'name'
,
'age'
));
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertNull
(
$results
->
first
()
->
title
);
$this
->
assertNull
(
$results
->
first
()
->
title
);
$this
->
assertEquals
(
9
,
$results
->
total
());
}
}
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment