Skip to content

Commit

Permalink
Merge pull request #886 from dbartenstein/feature/speed_up_get_deleted
Browse files Browse the repository at this point in the history
See #885: Very slow VersionQuerySet.get_deleted
  • Loading branch information
etianen committed Aug 18, 2021
2 parents 1cc4023 + 471d9e1 commit a2a8565
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.6 on 2021-08-16 18:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('reversion', '0001_squashed_0004_auto_20160611_1202'),
]

operations = [
migrations.AddIndex(
model_name='version',
index=models.Index(fields=['content_type', 'db'], name='reversion_v_content_f95daf_idx'),
),
]
8 changes: 7 additions & 1 deletion reversion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ def get_deleted(self, model, model_db=None):
latest_pk=models.Max("pk")
).order_by().values_list("latest_pk", flat=True)
# Perform the subquery.
return self.filter(pk__in=subquery)
# Filter by model to reduce query execution time.
return self.get_for_model(model, model_db=model_db).filter(pk__in=subquery)

def get_unique(self):
last_key = None
Expand Down Expand Up @@ -328,6 +329,11 @@ class Meta:
unique_together = (
("db", "content_type", "object_id", "revision"),
)
indexes = (
models.Index(
fields=["content_type", "db"]
),
)
ordering = ("-pk",)


Expand Down

0 comments on commit a2a8565

Please sign in to comment.