From 3046d2b28c82a24fe74e2a8cb813dff319b3bbe8 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 13 Oct 2023 09:46:30 -0700 Subject: [PATCH] drop 1k followers limit in UI fixes #670, at least for now. counting 1200 followers in prod was taking ~200ms; not great, but not horrible. should cache this eventually though! --- activitypub.py | 2 +- pages.py | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/activitypub.py b/activitypub.py index d3ed328..a393aca 100644 --- a/activitypub.py +++ b/activitypub.py @@ -905,7 +905,7 @@ def follower_collection(id, collection): count = Follower.query( Follower.status == 'active', prop == g.user.key, - ).count() + ).count() # TODO: cache, unify with pages.count_followers collection = { '@context': 'https://www.w3.org/ns/activitystreams', diff --git a/pages.py b/pages.py index d6ea118..9e2bb9e 100644 --- a/pages.py +++ b/pages.py @@ -4,6 +4,7 @@ import itertools import logging import os import re +import time from flask import g, render_template, request from google.cloud.ndb import tasklets @@ -20,8 +21,6 @@ from flask_app import app, cache from models import fetch_page, Follower, Object, PAGE_SIZE, PROTOCOLS from protocol import Protocol -FOLLOWERS_UI_LIMIT = 999 - # precompute this because we get a ton of requests for non-existing users # from weird open redirect referrers: # https://github.com/snarfed/bridgy-fed/issues/422 @@ -159,16 +158,18 @@ def followers_or_following(protocol, id, collection): ) +# TODO: cache? def count_followers(): - followers = Follower.query(Follower.to == g.user.key, - Follower.status == 'active')\ - .count(limit=FOLLOWERS_UI_LIMIT) - num_followers = f'{followers}{"+" if followers == FOLLOWERS_UI_LIMIT else ""}' + start = time.time() + num_followers = Follower.query(Follower.to == g.user.key, + Follower.status == 'active')\ + .count() + end = time.time() + logger.info(f"Loading {g.user.key.id()}'s followers took {end - start}s") - following = Follower.query(Follower.from_ == g.user.key, - Follower.status == 'active')\ - .count(limit=FOLLOWERS_UI_LIMIT) - num_following = f'{following}{"+" if following == FOLLOWERS_UI_LIMIT else ""}' + num_following = Follower.query(Follower.from_ == g.user.key, + Follower.status == 'active')\ + .count() return num_followers, num_following