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:
parent
4293acb3a3
commit
a54afd5210
@ -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"]
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user