From d27bad2a2bc4b0377c2e434441a01fffcbea58e8 Mon Sep 17 00:00:00 2001 From: Oleksandr Sorokin Date: Tue, 7 Nov 2023 09:08:01 +0100 Subject: [PATCH] fix: speed up get deleted. remove unnecessary subquery --- reversion/models.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reversion/models.py b/reversion/models.py index 4b245d92..c33d853c 100644 --- a/reversion/models.py +++ b/reversion/models.py @@ -168,12 +168,11 @@ def get_deleted(self, model, model_db=None): # conditional expressions are being supported since django 3.0 # DISTINCT ON works only for Postgres DB if connection.vendor == "postgresql" and django.VERSION >= (3, 0): - subquery = ( + return ( self.get_for_model(model, model_db=model_db) .filter(~models.Exists(model_qs)) .order_by("object_id", "-pk") .distinct("object_id") - .values("pk") ) else: subquery = (