mirror of
https://github.com/jointakahe/takahe.git
synced 2025-06-07 11:18:48 +00:00
Fix empty pagination
This commit is contained in:
parent
bb0ee1b152
commit
03bfc417df
1 changed files with 8 additions and 2 deletions
|
@ -95,11 +95,11 @@ class MastodonPaginator:
|
||||||
try:
|
try:
|
||||||
return PostInteraction.objects.get(pk=anchor_id[12:])
|
return PostInteraction.objects.get(pk=anchor_id[12:])
|
||||||
except PostInteraction.DoesNotExist:
|
except PostInteraction.DoesNotExist:
|
||||||
return PaginationResult.empty()
|
return None
|
||||||
try:
|
try:
|
||||||
return self.anchor_model.objects.get(pk=anchor_id)
|
return self.anchor_model.objects.get(pk=anchor_id)
|
||||||
except self.anchor_model.DoesNotExist:
|
except self.anchor_model.DoesNotExist:
|
||||||
return PaginationResult.empty()
|
return None
|
||||||
|
|
||||||
def paginate(
|
def paginate(
|
||||||
self,
|
self,
|
||||||
|
@ -111,12 +111,16 @@ class MastodonPaginator:
|
||||||
) -> PaginationResult:
|
) -> PaginationResult:
|
||||||
if max_id:
|
if max_id:
|
||||||
anchor = self.get_anchor(max_id)
|
anchor = self.get_anchor(max_id)
|
||||||
|
if anchor is None:
|
||||||
|
return PaginationResult.empty()
|
||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
**{self.sort_attribute + "__lt": getattr(anchor, self.sort_attribute)}
|
**{self.sort_attribute + "__lt": getattr(anchor, self.sort_attribute)}
|
||||||
)
|
)
|
||||||
|
|
||||||
if since_id:
|
if since_id:
|
||||||
anchor = self.get_anchor(since_id)
|
anchor = self.get_anchor(since_id)
|
||||||
|
if anchor is None:
|
||||||
|
return PaginationResult.empty()
|
||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
**{self.sort_attribute + "__gt": getattr(anchor, self.sort_attribute)}
|
**{self.sort_attribute + "__gt": getattr(anchor, self.sort_attribute)}
|
||||||
)
|
)
|
||||||
|
@ -125,6 +129,8 @@ class MastodonPaginator:
|
||||||
# Min ID requires items _immediately_ newer than specified, so we
|
# Min ID requires items _immediately_ newer than specified, so we
|
||||||
# invert the ordering to accommodate
|
# invert the ordering to accommodate
|
||||||
anchor = self.get_anchor(min_id)
|
anchor = self.get_anchor(min_id)
|
||||||
|
if anchor is None:
|
||||||
|
return PaginationResult.empty()
|
||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
**{self.sort_attribute + "__gt": getattr(anchor, self.sort_attribute)}
|
**{self.sort_attribute + "__gt": getattr(anchor, self.sort_attribute)}
|
||||||
).order_by(self.sort_attribute)
|
).order_by(self.sort_attribute)
|
||||||
|
|
Loading…
Reference in a new issue