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
a8918aca
Unverified
Commit
a8918aca
authored
Oct 31, 2019
by
Jens Segers
Committed by
GitHub
Oct 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1695 from josemiguelq/paginating
Improve pagination execution time
parents
cdc6e1d6
65a94df2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
+24
-14
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+24
-14
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
a8918aca
...
...
@@ -232,7 +232,7 @@ class Builder extends BaseBuilder
$wheres
=
$this
->
compileWheres
();
// Use MongoDB's aggregation framework when using grouping or aggregation functions.
if
(
$this
->
groups
||
$this
->
aggregate
||
$this
->
paginating
)
{
if
(
$this
->
groups
||
$this
->
aggregate
)
{
$group
=
[];
$unwinds
=
[];
...
...
@@ -267,24 +267,34 @@ class Builder extends BaseBuilder
$column
=
implode
(
'.'
,
$splitColumns
);
}
// Translate count into sum.
if
(
$function
==
'count'
)
{
// Null coalense only > 7.2
$aggregations
=
blank
(
$this
->
aggregate
[
'columns'
])
?
[]
:
$this
->
aggregate
[
'columns'
];
if
(
in_array
(
'*'
,
$aggregations
)
&&
$function
==
'count'
)
{
// When ORM is paginating, count doesnt need a aggregation, just a cursor operation
// elseif added to use this only in pagination
// https://docs.mongodb.com/manual/reference/method/cursor.count/
// count method returns int
$totalResults
=
$this
->
collection
->
count
(
$wheres
);
// Preserving format expected by framework
$results
=
[
[
'_id'
=>
null
,
'aggregate'
=>
$totalResults
]
];
return
$this
->
useCollections
?
new
Collection
(
$results
)
:
$results
;
}
elseif
(
$function
==
'count'
)
{
// Translate count into sum.
$group
[
'aggregate'
]
=
[
'$sum'
=>
1
];
}
// Pass other functions directly.
else
{
}
else
{
$group
[
'aggregate'
]
=
[
'$'
.
$function
=>
'$'
.
$column
];
}
}
}
// When using pagination, we limit the number of returned columns
// by adding a projection.
if
(
$this
->
paginating
)
{
foreach
(
$this
->
columns
as
$column
)
{
$this
->
projections
[
$column
]
=
1
;
}
}
// The _id field is mandatory when using grouping.
if
(
$group
&&
empty
(
$group
[
'_id'
]))
{
$group
[
'_id'
]
=
null
;
...
...
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