mirror of
https://github.com/etesync/server
synced 2024-11-24 17:58:07 +00:00
Optimize how we fetch the latest (current) revision
The way were were doing it was implicitly sorting the query items and it was causing millions of items to be sorted (even though the result should only have one) making it slow. By switching away from `get()` and `first()` we are telling django to not try to sort.
This commit is contained in:
parent
5f455e55b5
commit
2f1f95fea9
@ -96,7 +96,7 @@ class CollectionItem(models.Model):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def content(self) -> "CollectionItemRevision":
|
def content(self) -> "CollectionItemRevision":
|
||||||
return self.revisions.get(current=True)
|
return self.revisions.filter(current=True)[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def etag(self) -> str:
|
def etag(self) -> str:
|
||||||
|
@ -396,7 +396,7 @@ def item_create(item_model: CollectionItemIn, collection: models.Collection, val
|
|||||||
if not created:
|
if not created:
|
||||||
# We don't have to use select_for_update here because the unique constraint on current guards against
|
# We don't have to use select_for_update here because the unique constraint on current guards against
|
||||||
# the race condition. But it's a good idea because it'll lock and wait rather than fail.
|
# the race condition. But it's a good idea because it'll lock and wait rather than fail.
|
||||||
current_revision = instance.revisions.filter(current=True).select_for_update().first()
|
current_revision = instance.revisions.filter(current=True).select_for_update()[0]
|
||||||
assert current_revision is not None
|
assert current_revision is not None
|
||||||
current_revision.current = None
|
current_revision.current = None
|
||||||
current_revision.save()
|
current_revision.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user