Skip to content

Commit

Permalink
Stop querying deleted_at
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm committed Jun 14, 2021
1 parent 7c3ddb7 commit b5008a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
1 change: 0 additions & 1 deletion kpi/deployment_backends/kobocat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,6 @@ def __get_submissions_in_xml(self, **params):

queryset = ReadOnlyKobocatInstance.objects.filter(
xform_id=self.xform_id,
deleted_at=None
)

if len(instance_ids) > 0 or use_mongo:
Expand Down
16 changes: 3 additions & 13 deletions kpi/utils/mongo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ def encode(cls, key):

@classmethod
def get_count(
cls, mongo_userform_id, hide_deleted=True, query=None, instance_ids=None,
cls, mongo_userform_id, query=None, instance_ids=None,
permission_filters=None):

_, total_count = cls._get_cursor_and_count(
mongo_userform_id,
hide_deleted=hide_deleted,
fields={'_id': 1},
query=query,
instance_ids=instance_ids,
Expand All @@ -78,13 +77,12 @@ def get_count(

@classmethod
def get_instances(
cls, mongo_userform_id, hide_deleted=True, start=None, limit=None,
cls, mongo_userform_id, start=None, limit=None,
sort=None, fields=None, query=None, instance_ids=None,
permission_filters=None
):
cursor, total_count = cls._get_cursor_and_count(
mongo_userform_id,
hide_deleted=hide_deleted,
fields=fields,
query=query,
instance_ids=instance_ids,
Expand Down Expand Up @@ -252,7 +250,7 @@ def is_attribute_invalid(cls, key):
cls.KEY_WHITELIST and (key.startswith('$') or key.count('.') > 0)

@classmethod
def _get_cursor_and_count(cls, mongo_userform_id, hide_deleted=True,
def _get_cursor_and_count(cls, mongo_userform_id,
fields=None, query=None, instance_ids=None,
permission_filters=None):

Expand All @@ -271,14 +269,6 @@ def _get_cursor_and_count(cls, mongo_userform_id, hide_deleted=True,

query = {'$and': [query, permission_filters_query]}

if hide_deleted:
# display only active elements
deleted_at_query = {
'$or': [{'_deleted_at': {'$exists': False}},
{'_deleted_at': None}]}
# join existing query with deleted_at_query on an $and
query = {'$and': [query, deleted_at_query]}

query = cls.to_safe_dict(query, reading=True)

if len(fields) > 0:
Expand Down

0 comments on commit b5008a0

Please sign in to comment.