kopia lustrzana https://github.com/snarfed/bridgy-fed
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
rodzic
6c1565b087
commit
3046d2b28c
|
@ -905,7 +905,7 @@ def follower_collection(id, collection):
|
||||||
count = Follower.query(
|
count = Follower.query(
|
||||||
Follower.status == 'active',
|
Follower.status == 'active',
|
||||||
prop == g.user.key,
|
prop == g.user.key,
|
||||||
).count()
|
).count() # TODO: cache, unify with pages.count_followers
|
||||||
|
|
||||||
collection = {
|
collection = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
|
17
pages.py
17
pages.py
|
@ -4,6 +4,7 @@ import itertools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
from flask import g, render_template, request
|
from flask import g, render_template, request
|
||||||
from google.cloud.ndb import tasklets
|
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 models import fetch_page, Follower, Object, PAGE_SIZE, PROTOCOLS
|
||||||
from protocol import Protocol
|
from protocol import Protocol
|
||||||
|
|
||||||
FOLLOWERS_UI_LIMIT = 999
|
|
||||||
|
|
||||||
# precompute this because we get a ton of requests for non-existing users
|
# precompute this because we get a ton of requests for non-existing users
|
||||||
# from weird open redirect referrers:
|
# from weird open redirect referrers:
|
||||||
# https://github.com/snarfed/bridgy-fed/issues/422
|
# https://github.com/snarfed/bridgy-fed/issues/422
|
||||||
|
@ -159,16 +158,18 @@ def followers_or_following(protocol, id, collection):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: cache?
|
||||||
def count_followers():
|
def count_followers():
|
||||||
followers = Follower.query(Follower.to == g.user.key,
|
start = time.time()
|
||||||
|
num_followers = Follower.query(Follower.to == g.user.key,
|
||||||
Follower.status == 'active')\
|
Follower.status == 'active')\
|
||||||
.count(limit=FOLLOWERS_UI_LIMIT)
|
.count()
|
||||||
num_followers = f'{followers}{"+" if followers == FOLLOWERS_UI_LIMIT else ""}'
|
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,
|
num_following = Follower.query(Follower.from_ == g.user.key,
|
||||||
Follower.status == 'active')\
|
Follower.status == 'active')\
|
||||||
.count(limit=FOLLOWERS_UI_LIMIT)
|
.count()
|
||||||
num_following = f'{following}{"+" if following == FOLLOWERS_UI_LIMIT else ""}'
|
|
||||||
|
|
||||||
return num_followers, num_following
|
return num_followers, num_following
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue