Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Slightly more efficient version of the get_deleted implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
etianen committed Nov 22, 2010
1 parent 1c58d68 commit 249b686
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/reversion/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ def get_deleted(self, model_class, select_related=None):
content_type = ContentType.objects.get_for_model(model_class)
# HACK: This join can't be done in the database, due to incompatibilities
# between unicode object_ids and integer pks on strict backends like postgres.
versioned_pks = set(self.filter(content_type=content_type).values_list("object_id", flat=True).distinct())
for pk in model_class._default_manager.all().values_list("pk", flat=True).iterator():
try:
versioned_pks.remove(unicode(pk))
except KeyError:
pass
deleted = [self.get_deleted_object(model_class, pk, select_related) for pk in versioned_pks]
live_pks = frozenset(unicode(pk) for pk in model_class._default_manager.all().values_list("pk", flat=True))
deleted = []
for object_id in self.filter(content_type=content_type).values_list("object_id", flat=True).distinct().iterator():
if not object_id in live_pks:
deleted.append(self.get_deleted_object(model_class, object_id, select_related))
deleted.sort(lambda a, b: cmp(a.revision.date_created, b.revision.date_created))
return deleted


return deleted

0 comments on commit 249b686

Please sign in to comment.