From 01e165640e28fe5b202b34d8dc50392e32fdd9f9 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Wed, 11 Jul 2018 19:38:24 +0200 Subject: [PATCH] Remote the object service, use the backend instead --- app.py | 16 +++++++--------- config.py | 4 ---- utils/object_service.py | 21 --------------------- 3 files changed, 7 insertions(+), 34 deletions(-) delete mode 100644 utils/object_service.py diff --git a/app.py b/app.py index e58be68..e4f4995 100644 --- a/app.py +++ b/app.py @@ -41,7 +41,6 @@ import activitypub import config from activitypub import Box from activitypub import embed_collection -from config import ACTOR_SERVICE from config import ADMIN_API_KEY from config import BASE_URL from config import DB @@ -54,7 +53,6 @@ from config import JWT from config import KEY from config import ME from config import MEDIA_CACHE -from config import OBJECT_SERVICE from config import PASS from config import USERNAME from config import VERSION @@ -267,7 +265,7 @@ def get_actor(url): return None print(f"GET_ACTOR {url}") try: - return ACTOR_SERVICE.get(url) + return get_backend().fetch_iri(url) except (ActivityNotFoundError, ActivityGoneError): return f"Deleted<{url}>" @@ -794,7 +792,7 @@ def note_by_id(note_id): } ) ) - likes = [ACTOR_SERVICE.get(doc["activity"]["actor"]) for doc in likes] + likes = [get_backend().fetch_iri(doc["activity"]["actor"]) for doc in likes] shares = list( DB.activities.find( @@ -808,7 +806,7 @@ def note_by_id(note_id): } ) ) - shares = [ACTOR_SERVICE.get(doc["activity"]["actor"]) for doc in shares] + shares = [get_backend().fetch_iri(doc["activity"]["actor"]) for doc in shares] return render_template( "note.html", likes=likes, shares=shares, thread=thread, note=data @@ -1248,7 +1246,7 @@ def _user_api_arg(key: str, **kwargs): def _user_api_get_note(from_outbox: bool = False): oid = _user_api_arg("id") - note = ap.parse_activity(OBJECT_SERVICE.get(oid), expected=ActivityType.NOTE) + note = ap.parse_activity(get_backend().fetch_iri(oid), expected=ActivityType.NOTE) if from_outbox and not note.id.startswith(ID): raise NotFromOutboxError( f"cannot load {note.id}, id must be owned by the server" @@ -1436,7 +1434,7 @@ def api_new_note(): cc = [ID + "/followers"] if _reply: - reply = ap.parse_activity(OBJECT_SERVICE.get(_reply)) + reply = ap.fetch_remote_activity(_reply) cc.append(reply.attributedTo) for tag in tags: @@ -1547,7 +1545,7 @@ def followers(): ) followers, older_than, newer_than = paginated_query(DB.activities, q) - followers = [ACTOR_SERVICE.get(doc["activity"]["actor"]) for doc in followers] + followers = [get_backend().fetch_iri(doc["activity"]["actor"]) for doc in followers] return render_template( "followers.html", followers_data=followers, @@ -1571,7 +1569,7 @@ def following(): ) following, older_than, newer_than = paginated_query(DB.activities, q) - following = [ACTOR_SERVICE.get(doc["activity"]["object"]) for doc in following] + following = [get_backend.fetch_iri(doc["activity"]["object"]) for doc in following] return render_template( "following.html", following_data=following, diff --git a/config.py b/config.py index abb2187..9e7b844 100644 --- a/config.py +++ b/config.py @@ -15,7 +15,6 @@ from utils.key import KEY_DIR from utils.key import get_key from utils.key import get_secret_key from utils.media import MediaCache -from utils.object_service import ObjectService class ThemeStyle(Enum): @@ -148,6 +147,3 @@ ME = { }, "publicKey": KEY.to_dict(), } - - -OBJECT_SERVICE = ACTOR_SERVICE = ObjectService() diff --git a/utils/object_service.py b/utils/object_service.py deleted file mode 100644 index e46f9b1..0000000 --- a/utils/object_service.py +++ /dev/null @@ -1,21 +0,0 @@ -import logging - -from little_boxes.activitypub import get_backend - -logger = logging.getLogger(__name__) - - -class ObjectService(object): - def __init__(self): - logger.debug("Initializing ObjectService") - self._cache = {} - - def get(self, iri, reload_cache=False): - logger.info(f"get actor {iri} (reload_cache={reload_cache})") - - if not reload_cache and iri in self._cache: - return self._cache[iri] - - obj = get_backend().fetch_iri(iri) - self._cache[iri] = obj - return obj