stop using g.user in Follower.fetch_page

for #690
pull/731/head
Ryan Barrett 2023-11-19 20:39:05 -08:00
rodzic 29158e02e9
commit a1a7ceef51
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 10 dodań i 5 usunięć

Wyświetl plik

@ -1048,14 +1048,15 @@ class Follower(ndb.Model):
return follower
@staticmethod
def fetch_page(collection):
"""Fetches a page of Followers for the current user.
def fetch_page(collection, user):
"""Fetches a page of :class:`Follower`s for a given user.
Wraps :func:`fetch_page`. Paging uses the ``before`` and ``after`` query
parameters, if available in the request.
Args:
collection (str): ``followers`` or ``following``
user (User)
Returns:
(list of Follower, str, str) tuple: results, annotated with an extra
@ -1068,7 +1069,7 @@ class Follower(ndb.Model):
filter_prop = Follower.to if collection == 'followers' else Follower.from_
query = Follower.query(
Follower.status == 'active',
filter_prop == g.user.key,
filter_prop == user.key,
).order(-Follower.updated)
followers, before, after = fetch_page(query, Follower, by=Follower.updated)

Wyświetl plik

@ -53,6 +53,9 @@ def load_user(protocol, id):
protocol (str):
id (str):
Returns:
models.User:
Raises:
:class:`werkzeug.exceptions.HTTPException` on error or redirect
"""
@ -85,6 +88,7 @@ def load_user(protocol, id):
error(f'{protocol} user {id} not found', status=404)
assert not g.user.use_instead
return g.user
@app.route('/')
@ -158,9 +162,9 @@ def notifications(protocol, id):
@app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>/<any(followers,following):collection>')
@canonicalize_request_domain(common.PROTOCOL_DOMAINS, common.PRIMARY_DOMAIN)
def followers_or_following(protocol, id, collection):
load_user(protocol, id)
user = load_user(protocol, id)
followers, before, after = Follower.fetch_page(collection)
followers, before, after = Follower.fetch_page(collection, user)
num_followers, num_following = g.user.count_followers()
return render_template(
f'{collection}.html',