diff --git a/openlibrary/core/follows.py b/openlibrary/core/follows.py index 646f009c57e..4fad168d6ce 100644 --- a/openlibrary/core/follows.py +++ b/openlibrary/core/follows.py @@ -1,6 +1,5 @@ import logging -import web -from typing import cast, Any +from typing import cast from openlibrary.core.bookshelves import Bookshelves from . import db @@ -38,17 +37,21 @@ def is_subscribed(cls, subscriber, publisher): return len(subscription) @classmethod - def get_followers(cls, publisher): + def get_followers(cls, publisher, limit=None, offset=0): """Get publishers subscribers""" oldb = db.get_db() where = 'publisher=$publisher' subscribers = oldb.select( - cls.TABLENAME, where=where, vars={'publisher': publisher} + cls.TABLENAME, + where=where, + vars={'publisher': publisher}, + limit=limit, + offset=offset, ) return subscribers @classmethod - def get_following(cls, subscriber, exclude_disabled=False): + def get_following(cls, subscriber, limit=None, offset=0, exclude_disabled=False): """Get subscriber's subscriptions""" oldb = db.get_db() where = 'subscriber=$subscriber' @@ -58,6 +61,8 @@ def get_following(cls, subscriber, exclude_disabled=False): cls.TABLENAME, where=where, vars={'subscriber': subscriber}, + limit=limit, + offset=offset, ) return [dict(s) for s in subscriptions] diff --git a/openlibrary/plugins/upstream/account.py b/openlibrary/plugins/upstream/account.py index 513dbf50cd7..c3bd4b0c0f4 100644 --- a/openlibrary/plugins/upstream/account.py +++ b/openlibrary/plugins/upstream/account.py @@ -1134,14 +1134,29 @@ class my_follows(delegate.page): path = r"/people/([^/]+)/(followers|following)" def GET(self, username, key=""): - mb = MyBooksTemplate(username, 'following') + i = web.input(page=1) + page_size = 25 + + # Force invalid page query params to default to the first page + page = 1 if not i.page.isdigit() else max(1, int(i.page)) + offset = (page - 1) * page_size + follows = ( - PubSub.get_followers(username) + PubSub.get_followers(username, page_size, offset) if key == 'followers' - else PubSub.get_following(username) + else PubSub.get_following(username, page_size, offset) ) + follow_count = ( + PubSub.count_followers(username) + if key == 'followers' + else PubSub.count_following(username) + ) + + mb = MyBooksTemplate(username, 'following') manage = key == 'following' and mb.is_my_page - template = render['account/follows'](mb.user, follows, manage=manage) + template = render['account/follows']( + mb.user, follow_count, page, page_size, follows, manage=manage + ) return mb.render(header_title=_(key.capitalize()), template=template) diff --git a/openlibrary/templates/account/follows.html b/openlibrary/templates/account/follows.html index 426fa05d4da..d4dbec6e4d3 100644 --- a/openlibrary/templates/account/follows.html +++ b/openlibrary/templates/account/follows.html @@ -1,21 +1,24 @@ -$def with (user, follows=None, manage=False) +$def with (user, num_found, page, results_per_page, follows=None, manage=False) $if follows: $ username = user.key.split('/')[-1] $for follow in follows: +
+ $:macros.Pager(page, num_found, results_per_page) +
$else:

$_("There is nothing to see here yet.")