diff --git a/superdesk/datalayer.py b/superdesk/datalayer.py index 0925485f2a..bd5b04ffd6 100644 --- a/superdesk/datalayer.py +++ b/superdesk/datalayer.py @@ -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): diff --git a/superdesk/eve_backend.py b/superdesk/eve_backend.py index 6e030856e7..ff7ab0b174 100644 --- a/superdesk/eve_backend.py +++ b/superdesk/eve_backend.py @@ -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"):