kopia lustrzana https://github.com/snarfed/bridgy-fed
stop serving user pages and counting followers for protocol bot users
for #1561, #1678pull/1690/head
rodzic
18aa302dac
commit
cd28e4d68b
|
@ -31,6 +31,7 @@ from common import (
|
|||
DOMAIN_RE,
|
||||
long_to_base64,
|
||||
OLD_ACCOUNT_AGE,
|
||||
PROTOCOL_DOMAINS,
|
||||
report_error,
|
||||
unwrap,
|
||||
)
|
||||
|
@ -849,6 +850,11 @@ Welcome to Bridgy Fed! Your account will soon be bridged to {to_proto.PHRASE} at
|
|||
Returns:
|
||||
(int, int) tuple: (number of followers, number following)
|
||||
"""
|
||||
if self.key.id() in PROTOCOL_DOMAINS:
|
||||
# we don't store Followers for protocol bot users any more, so
|
||||
# follower counts are inaccurate, so don't return them
|
||||
return (0, 0)
|
||||
|
||||
num_followers = Follower.query(Follower.to == self.key,
|
||||
Follower.status == 'active')\
|
||||
.count_async()
|
||||
|
|
5
pages.py
5
pages.py
|
@ -25,7 +25,7 @@ from werkzeug.exceptions import NotFound
|
|||
from activitypub import ActivityPub, instance_actor
|
||||
from atproto import ATProto
|
||||
import common
|
||||
from common import CACHE_CONTROL, DOMAIN_RE
|
||||
from common import CACHE_CONTROL, DOMAIN_RE, PROTOCOL_DOMAINS
|
||||
from flask_app import app
|
||||
from flask import redirect
|
||||
import ids
|
||||
|
@ -68,6 +68,9 @@ def load_user(protocol, id):
|
|||
"""
|
||||
assert id
|
||||
|
||||
if id in PROTOCOL_DOMAINS:
|
||||
error(f'{protocol} user {id} not found', status=404)
|
||||
|
||||
cls = PROTOCOLS[protocol]
|
||||
|
||||
if cls.ABBREV == 'ap' and not id.startswith('@'):
|
||||
|
|
|
@ -453,6 +453,12 @@ class UserTest(TestCase):
|
|||
user.count_followers.cache.clear()
|
||||
self.assertEqual((1, 2), user.count_followers())
|
||||
|
||||
def test_count_followers_protocol_bot_user(self):
|
||||
bot = self.make_user(id='fa.brid.gy', cls=Web)
|
||||
Follower(from_=bot.key, to=Fake(id='b').key).put()
|
||||
Follower(from_=Fake(id='c').key, to=bot.key).put()
|
||||
self.assertEqual((0, 0), bot.count_followers())
|
||||
|
||||
def test_is_enabled_default_enabled_protocols(self):
|
||||
web = self.make_user('a.com', cls=Web)
|
||||
|
||||
|
|
|
@ -217,6 +217,11 @@ class PagesTest(TestCase):
|
|||
got = self.client.get('/web/user.com?before=2024-01-01+01:01:01&after=2023-01-01+01:01:01')
|
||||
self.assert_equals(400, got.status_code)
|
||||
|
||||
def test_user_protocol_bot_user(self):
|
||||
bot = self.make_user(id='fa.brid.gy', cls=Web)
|
||||
got = self.client.get(f'/web/fa.brid.gy')
|
||||
self.assert_equals(404, got.status_code)
|
||||
|
||||
def test_update_profile(self):
|
||||
self.make_user('fake:user', cls=Fake)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue