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!
pull/682/head
Ryan Barrett 2023-10-13 09:46:30 -07:00
rodzic 6c1565b087
commit 3046d2b28c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 12 dodań i 11 usunięć

Wyświetl plik

@ -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',

Wyświetl plik

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