From f5c60a1d9b971f9f22e9c3ff765d3ec257a01b32 Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Wed, 16 Dec 2020 14:24:57 +0300 Subject: [PATCH] Disable "form_versions" calculation for forms after a configurable limit Disable "form_versions" calculation for forms that have submissions that surpass the "SUBMISSION_RETRIEVAL_THRESHOLD" setting --- onadata/libs/serializers/xform_serializer.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/onadata/libs/serializers/xform_serializer.py b/onadata/libs/serializers/xform_serializer.py index 77a8b245ba..b3acac8163 100644 --- a/onadata/libs/serializers/xform_serializer.py +++ b/onadata/libs/serializers/xform_serializer.py @@ -36,6 +36,11 @@ get_enketo_urls, get_form_url) +SUBMISSION_RETRIEVAL_THRESHOLD = getattr(settings, + "SUBMISSION_RETRIEVAL_THRESHOLD", + 10000) + + def _create_enketo_urls(request, xform): """ Generate enketo urls for a form @@ -388,6 +393,8 @@ def get_form_versions(self, obj): if versions: return versions + elif obj.num_of_submissions > SUBMISSION_RETRIEVAL_THRESHOLD: + return [] versions = list( Instance.objects.filter(xform=obj, deleted_at__isnull=True)