From 4640d3649bd73b62dd2b1c301f7f1ebacba8fe4f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 16 Feb 2021 19:44:31 +0100 Subject: Improve document generation perf --- archaeological_warehouse/models.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'archaeological_warehouse/models.py') diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 06c7cdcd8..cb144270b 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -651,6 +651,9 @@ class Container(DocumentItem, Merge, LightHistorizedItem, STATISTIC_MODALITIES = [ key for key, lbl in STATISTIC_MODALITIES_OPTIONS.items()] + GET_VALUES_EXCLUDE_FIELDS = ValueGetter.GET_VALUES_EXCLUDE_FIELDS + [ + "inside_container", "parent"] + # search parameters EXTRA_REQUEST_KEYS = { 'location': 'location__pk', @@ -1341,16 +1344,17 @@ class Container(DocumentItem, Merge, LightHistorizedItem, def get_values(self, prefix='', no_values=False, filtr=None, **kwargs): values = super(Container, self).get_values( prefix=prefix, no_values=no_values, filtr=filtr, **kwargs) - if (not filtr or prefix + 'finds' in filtr) and ( - not prefix.startswith("container_") and not - prefix.startswith("container_ref_")): + from_find = prefix.startswith("container_") or \ + prefix.startswith("container_ref_") + if (not filtr or prefix + 'finds' in filtr) and not from_find: kwargs["exclude"] = [prefix + "container", prefix + "container_ref"] # prevent recursive call values[prefix + 'finds'] = [ f.get_values( prefix=prefix, no_values=True, filtr=None, **kwargs) for f in self.finds.distinct().all()] - if (not filtr or prefix + 'operation' in filtr or + if not from_find and ( + not filtr or prefix + 'operation' in filtr or prefix + "context_record" in filtr) and self.finds.count(): # assume that only one operation is in this container # you should know what you are doing when using theses variables -- cgit v1.2.3