From 99efe6b290dc07a117764904e41f59480d34f4b8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 26 Apr 2021 10:11:13 -0700 Subject: [PATCH 1/2] Limit how many notifications are loaded --- bookwyrm/views/notifications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/notifications.py b/bookwyrm/views/notifications.py index e0e2102d7..0324f5956 100644 --- a/bookwyrm/views/notifications.py +++ b/bookwyrm/views/notifications.py @@ -16,7 +16,7 @@ class Notifications(View): notifications = request.user.notification_set.all().order_by("-created_date") unread = [n.id for n in notifications.filter(read=False)] data = { - "notifications": notifications, + "notifications": notifications[:50], "unread": unread, } notifications.update(read=True) From 786cf4fb977857e8e441fbcbec4ca47f430dc04f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 26 Apr 2021 10:26:27 -0700 Subject: [PATCH 2/2] Paginate followers/following pages --- bookwyrm/templates/user/followers.html | 2 ++ bookwyrm/templates/user/following.html | 2 ++ bookwyrm/views/notifications.py | 2 +- bookwyrm/views/user.py | 6 ++++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/user/followers.html b/bookwyrm/templates/user/followers.html index 45d87a3d4..b294db909 100644 --- a/bookwyrm/templates/user/followers.html +++ b/bookwyrm/templates/user/followers.html @@ -29,4 +29,6 @@
{% blocktrans with username=user.display_name %}{{ username }} has no followers{% endblocktrans %}
{% endif %} + +{% include 'snippets/pagination.html' with page=followers path=request.path %} {% endblock %} diff --git a/bookwyrm/templates/user/following.html b/bookwyrm/templates/user/following.html index 5904c1bbe..38c01ad27 100644 --- a/bookwyrm/templates/user/following.html +++ b/bookwyrm/templates/user/following.html @@ -29,4 +29,6 @@
{% blocktrans with username=user|username %}{{ username }} isn't following any users{% endblocktrans %}
{% endif %} + +{% include 'snippets/pagination.html' with page=following path=request.path %} {% endblock %} diff --git a/bookwyrm/views/notifications.py b/bookwyrm/views/notifications.py index 0324f5956..3d08cade5 100644 --- a/bookwyrm/views/notifications.py +++ b/bookwyrm/views/notifications.py @@ -16,7 +16,7 @@ class Notifications(View): notifications = request.user.notification_set.all().order_by("-created_date") unread = [n.id for n in notifications.filter(read=False)] data = { - "notifications": notifications[:50], + "notifications": notifications[:50], "unread": unread, } notifications.update(read=True) diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index 05fdb6069..d394c1d73 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -106,10 +106,11 @@ class Followers(View): if is_api_request(request): return ActivitypubResponse(user.to_followers_activity(**request.GET)) + paginated = Paginator(user.followers.all(), PAGE_LENGTH) data = { "user": user, "is_self": request.user.id == user.id, - "followers": user.followers.all(), + "followers": paginated.page(request.GET.get("page", 1)), } return TemplateResponse(request, "user/followers.html", data) @@ -131,10 +132,11 @@ class Following(View): if is_api_request(request): return ActivitypubResponse(user.to_following_activity(**request.GET)) + paginated = Paginator(user.followers.all(), PAGE_LENGTH) data = { "user": user, "is_self": request.user.id == user.id, - "following": user.following.all(), + "following": paginated.page(request.GET.get("page", 1)), } return TemplateResponse(request, "user/following.html", data)