Merge pull request #1006 from bookwyrm-social/queryset-performance

Queryset performance
This commit is contained in:
Mouse Reeve 2021-04-26 10:44:26 -07:00 committed by GitHub
commit 247850e49d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View file

@ -29,4 +29,6 @@
<div>{% blocktrans with username=user.display_name %}{{ username }} has no followers{% endblocktrans %}</div>
{% endif %}
</div>
{% include 'snippets/pagination.html' with page=followers path=request.path %}
{% endblock %}

View file

@ -29,4 +29,6 @@
<div>{% blocktrans with username=user|username %}{{ username }} isn't following any users{% endblocktrans %}</div>
{% endif %}
</div>
{% include 'snippets/pagination.html' with page=following path=request.path %}
{% endblock %}

View file

@ -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)

View file

@ -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)