mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-29 02:31:00 +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:
|
||||
return PostInteraction.objects.get(pk=anchor_id[12:])
|
||||
except PostInteraction.DoesNotExist:
|
||||
return PaginationResult.empty()
|
||||
return None
|
||||
try:
|
||||
return self.anchor_model.objects.get(pk=anchor_id)
|
||||
except self.anchor_model.DoesNotExist:
|
||||
return PaginationResult.empty()
|
||||
return None
|
||||
|
||||
def paginate(
|
||||
self,
|
||||
|
@ -111,12 +111,16 @@ class MastodonPaginator:
|
|||
) -> PaginationResult:
|
||||
if max_id:
|
||||
anchor = self.get_anchor(max_id)
|
||||
if anchor is None:
|
||||
return PaginationResult.empty()
|
||||
queryset = queryset.filter(
|
||||
**{self.sort_attribute + "__lt": getattr(anchor, self.sort_attribute)}
|
||||
)
|
||||
|
||||
if since_id:
|
||||
anchor = self.get_anchor(since_id)
|
||||
if anchor is None:
|
||||
return PaginationResult.empty()
|
||||
queryset = queryset.filter(
|
||||
**{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
|
||||
# invert the ordering to accommodate
|
||||
anchor = self.get_anchor(min_id)
|
||||
if anchor is None:
|
||||
return PaginationResult.empty()
|
||||
queryset = queryset.filter(
|
||||
**{self.sort_attribute + "__gt": getattr(anchor, self.sort_attribute)}
|
||||
).order_by(self.sort_attribute)
|
||||
|
|
Loading…
Reference in a new issue