1
0
mirror of https://github.com/etesync/server synced 2024-11-18 23:08:08 +00:00

Optimize stoken-using functions to only account for current revisions.

No need to account for revisions that are not current when calculating stokens
because those, by definition, are not the latest ones, and therefore won't have
the most recent stokens.

This becomes a problem when collections have many associated revisions.
This commit is contained in:
Tom Hacohen 2023-08-15 20:21:23 -04:00
parent 4293acb3a3
commit a54afd5210
2 changed files with 3 additions and 3 deletions

View File

@ -66,7 +66,7 @@ class Collection(models.Model):
@cached_property
def stoken(self) -> str:
stoken_id = (
self.__class__.objects.filter(main_item=self.main_item)
self.__class__.objects.filter(main_item=self.main_item, items__revisions__current=True)
.annotate(max_stoken=self.stoken_annotation)
.values("max_stoken")
.first()["max_stoken"]

View File

@ -208,7 +208,7 @@ def collection_list_common(
prefetch: Prefetch,
) -> CollectionListResponse:
result, new_stoken_obj, done = filter_by_stoken_and_limit(
stoken, limit, queryset, models.Collection.stoken_annotation
stoken, limit, queryset.filter(items__revisions__current=True), models.Collection.stoken_annotation
)
new_stoken = new_stoken_obj and new_stoken_obj.uid
context = Context(user, prefetch)
@ -428,7 +428,7 @@ def item_list_common(
prefetch: Prefetch,
) -> CollectionItemListResponse:
result, new_stoken_obj, done = filter_by_stoken_and_limit(
stoken, limit, queryset, models.CollectionItem.stoken_annotation
stoken, limit, queryset.filter(revisions__current=True), models.CollectionItem.stoken_annotation
)
new_stoken = new_stoken_obj and new_stoken_obj.uid
context = Context(user, prefetch)