From 7dda74421fb4e17a10add5ec33a66fe150416151 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 24 Feb 2025 15:38:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(back)=20extract=20ancestor?= =?UTF-8?q?=20deleted=5Fat=20directly=20from=20db=20in=20restore=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the restore method, all the ancestors with a deleted_at date set are extracted from the database and then the oldest value is extracted using the min python function. This usage of min can be removed by sorting directly the deleted_at at the databse level and then fetching the first one. It's faster and easier to maintain. --- src/backend/core/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 7ff3daba..17b6e2b0 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -794,9 +794,11 @@ class Document(MP_Node, BaseModel): ancestors_deleted_at = ( self.get_ancestors() .filter(deleted_at__isnull=False) + .order_by("deleted_at") .values_list("deleted_at", flat=True) + .first() ) - self.ancestors_deleted_at = min(ancestors_deleted_at, default=None) + self.ancestors_deleted_at = ancestors_deleted_at self.save() # Update descendants excluding those who were deleted prior to the deletion of the