From d6a10b4be0ef4743fec8e7a0642e6ab40fb1671a Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Wed, 24 Apr 2024 17:06:25 -0700 Subject: [PATCH] update profile button: make receive task instead of running it inline --- pages.py | 15 ++++++--------- protocol.py | 2 +- tests/test_pages.py | 5 +---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pages.py b/pages.py index 49c27d5..9834482 100644 --- a/pages.py +++ b/pages.py @@ -170,19 +170,16 @@ def update_profile(protocol, id): try: profile_obj = user.load(user.profile_id(), remote=True) - if profile_obj: - msg, status = user.receive(profile_obj) - else: - status = 400 - msg = "couldn't fetch profile" - except (requests.RequestException, werkzeug.exceptions.HTTPException) as e: - status, msg = util.interpret_http_exception(e) + _, msg = util.interpret_http_exception(e) + flash(f"Couldn't update profile for {user.handle_or_id()}: {msg}") - if int(status) // 100 == 2: + if profile_obj: + common.create_task(queue='receive', obj=profile_obj.key.urlsafe(), + authed_as=id) flash(f'Updating profile for {user.handle_or_id()}') else: - flash(f"Couldn't update profile for {user.handle_or_id()}: {msg}") + flash(f"Couldn't update profile for {user.handle_or_id()}") return redirect(user.user_page_path(), code=302) diff --git a/protocol.py b/protocol.py index aeaac9a..4a87d52 100644 --- a/protocol.py +++ b/protocol.py @@ -1328,8 +1328,8 @@ class Protocol: if obj.source_protocol: logger.warning(f'Object {obj.key.id()} changed protocol from {obj.source_protocol} to {cls.LABEL} ?!') obj.source_protocol = cls.LABEL - obj.put() + obj.put() with objects_cache_lock: objects_cache[id] = obj return obj diff --git a/tests/test_pages.py b/tests/test_pages.py index b85c32e..cceab62 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -184,10 +184,7 @@ class PagesTest(TestCase): get_flashed_messages()) self.assertEqual(['fake:user'], Fake.fetched) - self.assert_object('fake:user', source_protocol='fake', our_as1={ - **actor, - 'updated': '2022-01-02T03:04:05+00:00', - }) + self.assert_object('fake:user', source_protocol='fake', our_as1=actor) def test_followers(self): Follower.get_or_create(