Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only run cursor.count when requested #2469

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading