Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ParsePy
Overview
Overview
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
OpenEdx
ParsePy
Commits
2f6bfd20
Commit
2f6bfd20
authored
Mar 27, 2013
by
David Robinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Altered count method to use count query rather than fetching all objects and finding the length
parent
f94ed539
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
3 deletions
+13
-3
parse_rest/query.py
+13
-3
No files found.
parse_rest/query.py
View file @
2f6bfd20
...
...
@@ -34,6 +34,11 @@ class QueryManager(object):
uri
=
self
.
model_class
.
ENDPOINT_ROOT
return
[
klass
(
**
it
)
for
it
in
klass
.
GET
(
uri
,
**
kw
)
.
get
(
'results'
)]
def
_count
(
self
,
**
kw
):
kw
.
update
({
"count"
:
1
,
"limit"
:
0
})
return
self
.
model_class
.
GET
(
self
.
model_class
.
ENDPOINT_ROOT
,
**
kw
)
.
get
(
'count'
)
def
all
(
self
):
return
Queryset
(
self
)
...
...
@@ -102,12 +107,18 @@ class Queryset(object):
def
__iter__
(
self
):
return
iter
(
self
.
_fetch
())
def
_fetch
(
self
):
def
_fetch
(
self
,
count
=
False
):
"""
Return a list of objects matching query, or if count == True return
only the number of objects matching.
"""
options
=
dict
(
self
.
_options
)
# make a local copy
if
self
.
_where
:
# JSON encode WHERE values
where
=
json
.
dumps
(
self
.
_where
)
options
.
update
({
'where'
:
where
})
if
count
:
return
self
.
_manager
.
_count
(
**
options
)
return
self
.
_manager
.
_fetch
(
**
options
)
...
...
@@ -125,8 +136,7 @@ class Queryset(object):
return
self
def
count
(
self
):
results
=
self
.
_fetch
()
return
len
(
results
)
return
self
.
_fetch
(
count
=
True
)
def
exists
(
self
):
results
=
self
.
_fetch
()
...
...
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