Skip to content

Commit

Permalink
fix(form): speed up copying of documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz committed Sep 26, 2024
1 parent 9163635 commit fac7a98
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion caluma/caluma_form/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,15 @@ def set_family(self, root_doc):

def copy(self, family=None, user=None):
"""Create a copy including all its answers."""
from caluma.caluma_form.utils import recalculate_answers_from_document

# defer calculated questions, as many unecessary recomputations will happen otherwise
meta = dict(self.meta)
meta["_defer_calculation"] = True

new_document = type(self).objects.create(
form=self.form,
meta=dict(self.meta),
meta=meta,
source=self,
family=family,
created_by_user=user.username if user else None,
Expand All @@ -416,6 +421,10 @@ def copy(self, family=None, user=None):
document_family=family, to_document=new_document, user=user
)

new_document.meta.pop("_defer_calculation", None)
new_document.save()
recalculate_answers_from_document(new_document)

return new_document

@cached_property
Expand Down

0 comments on commit fac7a98

Please sign in to comment.