From 7d40dc01130864aa60687f5d2cafe7233e561423 Mon Sep 17 00:00:00 2001 From: Joel Auterson Date: Sun, 5 Nov 2023 00:23:21 +0000 Subject: [PATCH 1/2] Fix cache in Bluesky --- granary/bluesky.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/granary/bluesky.py b/granary/bluesky.py index a67be35a..8f16ca83 100644 --- a/granary/bluesky.py +++ b/granary/bluesky.py @@ -1038,14 +1038,14 @@ def get_activities_response(self, user_id=None, group_id=None, app_id=None, if fetch_likes and like_count and like_count != cache.get('ABL ' + id): likers = self.client.app.bsky.feed.getLikes({}, uri=bs_post.get('uri')) tags.extend(self._make_like(bs_post, l.get('actor')) for l in likers.get('likes')) - cache['ABL ' + id] = count + cache['ABL ' + id] = like_count # Reposts repost_count = bs_post.get('repostCount') if fetch_shares and repost_count and repost_count != cache.get('ABRP ' + id): reposters = self.client.app.bsky.feed.getRepostedBy({}, uri=bs_post.get('uri')) tags.extend(self._make_share(bs_post, r) for r in reposters.get('repostedBy')) - cache['ABRP ' + id] = count + cache['ABRP ' + id] = repost_count # Replies reply_count = bs_post.get('replyCount') @@ -1057,7 +1057,7 @@ def get_activities_response(self, user_id=None, group_id=None, app_id=None, obj['replies'] = { 'items': replies, } - cache['ABR ' + id] = count + cache['ABR ' + id] = reply_count resp = self.make_activities_base_response(util.trim_nulls(activities)) return resp From ce99e82b888e698307d74b14a9f0b05776e7e096 Mon Sep 17 00:00:00 2001 From: Joel Auterson Date: Sun, 5 Nov 2023 11:24:00 +0000 Subject: [PATCH 2/2] Add tests for cache --- granary/tests/test_bluesky.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/granary/tests/test_bluesky.py b/granary/tests/test_bluesky.py index fc98a0f5..cbee0fc6 100644 --- a/granary/tests/test_bluesky.py +++ b/granary/tests/test_bluesky.py @@ -993,9 +993,10 @@ def test_get_activities_with_likes(self, mock_get): }) ] + cache = {} self.assert_equals( [POST_AUTHOR_PROFILE_WITH_LIKES_AS], - self.bs.get_activities(fetch_likes=True) + self.bs.get_activities(fetch_likes=True, cache=cache) ) mock_get.assert_any_call( 'https://bsky.social/xrpc/app.bsky.feed.getTimeline', @@ -1015,6 +1016,7 @@ def test_get_activities_with_likes(self, mock_get): 'User-Agent': util.user_agent, }, ) + self.assert_equals(1, cache.get('ABL at://did/app.bsky.feed.post/tid')) @patch('requests.get') def test_get_activities_with_reposts(self, mock_get): @@ -1030,9 +1032,10 @@ def test_get_activities_with_reposts(self, mock_get): }) ] + cache = {} self.assert_equals( [POST_AUTHOR_PROFILE_WITH_REPOSTS_AS], - self.bs.get_activities(fetch_shares=True) + self.bs.get_activities(fetch_shares=True, cache=cache) ) mock_get.assert_any_call( 'https://bsky.social/xrpc/app.bsky.feed.getTimeline', @@ -1052,6 +1055,7 @@ def test_get_activities_with_reposts(self, mock_get): 'User-Agent': util.user_agent, }, ) + self.assert_equals(1, cache.get('ABRP at://did/app.bsky.feed.post/tid')) @patch('requests.get') def test_get_activities_include_shares(self, mock_get): @@ -1077,8 +1081,9 @@ def test_get_activities_with_replies(self, mock_get): }) ] + cache = {} self.assert_equals([THREAD_AS], - self.bs.get_activities(fetch_replies=True)) + self.bs.get_activities(fetch_replies=True, cache=cache)) mock_get.assert_any_call( 'https://bsky.social/xrpc/app.bsky.feed.getTimeline', json=None, @@ -1097,6 +1102,7 @@ def test_get_activities_with_replies(self, mock_get): 'User-Agent': util.user_agent, }, ) + self.assert_equals(1, cache.get('ABR at://did/app.bsky.feed.post/tid')) @patch('requests.get') def test_get_actor(self, mock_get):