Skip to content

Commit

Permalink
only run cursor.count when requested (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek authored Sep 1, 2023
1 parent d9fee6b commit e83c3f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions superdesk/datalayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ def init_elastic(self, app, raise_on_mapping_error=False):
finally:
unlock("elastic")

def find(self, resource, req, lookup, perform_count=None):
def find(self, resource, req, lookup, perform_count=True):
cursor = superdesk.get_resource_service(resource).get(req=req, lookup=lookup)
return cursor, cursor.count()
if perform_count:
return cursor, cursor.count()
return cursor, None

def find_all(self, resource, max_results=1000):
req = ParsedRequest()
req.max_results = max_results
cursor, count = self._backend(resource).find(resource, req, None)
cursor, _ = self._backend(resource).find(resource, req, None, perform_count=False)
return cursor

def find_one(self, resource, req, check_auth_value=True, force_auth_field_projection=False, **lookup):
Expand Down
4 changes: 2 additions & 2 deletions superdesk/eve_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ def get(self, endpoint_name, req, lookup, **kwargs):
backend = self._lookup_backend(endpoint_name, fallback=True)
is_mongo = self._backend(endpoint_name) == backend

cursor, count = backend.find(endpoint_name, req, lookup)
cursor, count = backend.find(endpoint_name, req, lookup, perform_count=req.if_modified_since)

if req.if_modified_since and count:
# fetch all items, not just updated
req.if_modified_since = None
cursor, count = backend.find(endpoint_name, req, lookup)
cursor, count = backend.find(endpoint_name, req, lookup, perform_count=False)

source_config = app.config["DOMAIN"][endpoint_name]
if is_mongo and source_config.get("collation"):
Expand Down

0 comments on commit e83c3f9

Please sign in to comment.