♻️(back) extract ancestor deleted_at directly from db in restore method

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.
This commit is contained in:
Manuel Raynaud
2025-02-24 15:38:27 +01:00
parent 9c25b684e3
commit 7dda74421f

View File

@@ -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