noop: rename get_for_copy[ies] => get_for_original[s]

pull/708/head
Ryan Barrett 2023-11-02 12:18:08 -07:00
rodzic 02e8208e32
commit 9aff3122c0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 11 dodań i 11 usunięć

4
ids.py
Wyświetl plik

@ -33,7 +33,7 @@ def translate_user_id(*, id, from_proto, to_proto):
user = from_proto.get_by_id(id)
return user.atproto_did if user else None
case 'atproto', _:
user = models.get_for_copy(id)
user = models.get_original(id)
return user.key.id() if user else None
case _, 'activitypub':
return subdomain_wrap(from_proto, f'/ap/{id}')
@ -118,7 +118,7 @@ def translate_object_id(*, id, from_proto, to_proto):
for copy in obj.copies:
if copy.protocol in (to_proto.LABEL, to_proto.ABBREV):
return copy.uri
orig = models.get_for_copy(id)
orig = models.get_original(id)
if orig:
return orig.key.id()
logger.warning(f"Can't translate {id} to {to_proto} , haven't copied it to/from there yet!")

Wyświetl plik

@ -934,7 +934,7 @@ class Object(StringIdModel):
return
origs = get_for_copies(ids)
origs = get_originals(ids)
replaced = False
def replace(obj, field):
@ -1139,7 +1139,7 @@ def fetch_page(query, model_class, by=None):
return results, new_before, new_after
def get_for_copy(copy_id, keys_only=None):
def get_original(copy_id, keys_only=None):
"""Fetches a user or object with a given id in copies.
Thin wrapper around :func:`get_copies` that returns the first
@ -1152,12 +1152,12 @@ def get_for_copy(copy_id, keys_only=None):
Returns:
User or Object:
"""
got = get_for_copies([copy_id], keys_only=keys_only)
got = get_originals([copy_id], keys_only=keys_only)
if got:
return got[0]
def get_for_copies(copy_ids, keys_only=None):
def get_originals(copy_ids, keys_only=None):
"""Fetches users (across all protocols) for a given set of copies.
Args:

Wyświetl plik

@ -18,7 +18,7 @@ import common
from common import add, DOMAIN_BLOCKLIST, DOMAINS, error, subdomain_wrap
from flask_app import app
from ids import translate_object_id
from models import Follower, get_for_copies, Object, PROTOCOLS, Target, User
from models import Follower, get_originals, Object, PROTOCOLS, Target, User
SUPPORTED_TYPES = (
'accept',
@ -935,7 +935,7 @@ class Protocol:
# TODO: remove this? seems unnecessary now that receive calls resolve_ids?
if target_uris:
origs = {key.id() for key in get_for_copies(target_uris, keys_only=True)}
origs = {key.id() for key in get_originals(target_uris, keys_only=True)}
if origs:
target_uris |= origs
logger.info(f'Added originals: {origs}')

Wyświetl plik

@ -790,8 +790,8 @@ class ObjectTest(TestCase):
},
}, obj.our_as1)
def test_get_for_copies(self):
self.assertEqual([], models.get_for_copies(['foo', 'did:plc:bar']))
def test_get_originals(self):
self.assertEqual([], models.get_originals(['foo', 'did:plc:bar']))
obj = self.store_object(id='fake:post',
copies=[Target(uri='other:foo', protocol='other')])
@ -799,7 +799,7 @@ class ObjectTest(TestCase):
copies=[Target(uri='fake:bar', protocol='fake')])
self.assert_entities_equal(
[obj, user], models.get_for_copies(['other:foo', 'fake:bar', 'baz']))
[obj, user], models.get_originals(['other:foo', 'fake:bar', 'baz']))
class FollowerTest(TestCase):