mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Rename remove_object_from_related_stores
This makes the stores argument required, making it simpler to change the code.
This commit is contained in:
parent
8053f49acc
commit
68c6a9e748
6 changed files with 30 additions and 30 deletions
|
@ -516,8 +516,8 @@ def remove_status_task(status_ids):
|
|||
|
||||
for stream in streams.values():
|
||||
for status in statuses:
|
||||
stream.remove_object_from_related_stores(
|
||||
status, stores=stream.get_stores_for_object(status)
|
||||
stream.remove_object_from_stores(
|
||||
status, stream.get_stores_for_object(status)
|
||||
)
|
||||
|
||||
|
||||
|
@ -568,9 +568,9 @@ def handle_boost_task(boost_id):
|
|||
for stream in streams.values():
|
||||
# people who should see the boost (not people who see the original status)
|
||||
audience = stream.get_stores_for_object(instance)
|
||||
stream.remove_object_from_related_stores(boosted, stores=audience)
|
||||
stream.remove_object_from_stores(boosted, audience)
|
||||
for status in old_versions:
|
||||
stream.remove_object_from_related_stores(status, stores=audience)
|
||||
stream.remove_object_from_stores(status, audience)
|
||||
|
||||
|
||||
def get_status_type(status):
|
||||
|
|
|
@ -232,7 +232,7 @@ def remove_list_task(list_id, re_add=False):
|
|||
|
||||
# delete for every store
|
||||
stores = [ListsStream().stream_id(idx) for idx in stores]
|
||||
ListsStream().remove_object_from_related_stores(list_id, stores=stores)
|
||||
ListsStream().remove_object_from_stores(list_id, stores)
|
||||
|
||||
if re_add:
|
||||
add_list_task.delay(list_id)
|
||||
|
|
|
@ -32,14 +32,14 @@ class RedisStore(ABC):
|
|||
# and go!
|
||||
return pipeline.execute()
|
||||
|
||||
def remove_object_from_related_stores(self, obj, stores=None):
|
||||
# pylint: disable=no-self-use
|
||||
def remove_object_from_stores(self, obj, stores):
|
||||
"""remove an object from all stores"""
|
||||
# if the stoers are provided, the object can just be an id
|
||||
if stores and isinstance(obj, int):
|
||||
obj_id = obj
|
||||
else:
|
||||
obj_id = obj.id
|
||||
stores = self.get_stores_for_object(obj) if stores is None else stores
|
||||
pipeline = r.pipeline()
|
||||
for store in stores:
|
||||
pipeline.zrem(store, -1, obj_id)
|
||||
|
|
|
@ -254,8 +254,8 @@ def rerank_user_task(user_id, update_only=False):
|
|||
def remove_user_task(user_id):
|
||||
"""do the hard work in celery"""
|
||||
user = models.User.objects.get(id=user_id)
|
||||
suggested_users.remove_object_from_related_stores(
|
||||
user, stores=suggested_users.get_stores_for_object(user)
|
||||
suggested_users.remove_object_from_stores(
|
||||
user, suggested_users.get_stores_for_object(user)
|
||||
)
|
||||
|
||||
|
||||
|
@ -270,8 +270,8 @@ def remove_suggestion_task(user_id, suggested_user_id):
|
|||
def bulk_remove_instance_task(instance_id):
|
||||
"""remove a bunch of users from recs"""
|
||||
for user in models.User.objects.filter(federated_server__id=instance_id):
|
||||
suggested_users.remove_object_from_related_stores(
|
||||
user, stores=suggested_users.get_stores_for_object(user)
|
||||
suggested_users.remove_object_from_stores(
|
||||
user, suggested_users.get_stores_for_object(user)
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class Activitystreams(TestCase):
|
|||
def test_remove_status_task(self):
|
||||
"""remove a status from all streams"""
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_stores"
|
||||
) as mock:
|
||||
activitystreams.remove_status_task(self.status.id)
|
||||
self.assertEqual(mock.call_count, 3)
|
||||
|
@ -132,8 +132,8 @@ class Activitystreams(TestCase):
|
|||
self.assertEqual(args[0], self.local_user)
|
||||
self.assertEqual(args[1], self.another_user)
|
||||
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_boost_to_another_timeline(self, *_):
|
||||
"""boost from a non-follower doesn't remove original status from feed"""
|
||||
|
@ -144,7 +144,7 @@ class Activitystreams(TestCase):
|
|||
user=self.another_user,
|
||||
)
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||
) as mock:
|
||||
activitystreams.handle_boost_task(boost.id)
|
||||
|
||||
|
@ -152,10 +152,10 @@ class Activitystreams(TestCase):
|
|||
self.assertEqual(mock.call_count, 1)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertEqual(call_args[1]["stores"], [f"{self.another_user.id}-home"])
|
||||
self.assertEqual(call_args[0][1], [f"{self.another_user.id}-home"])
|
||||
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_boost_to_another_timeline_remote(self, *_):
|
||||
"""boost from a remote non-follower doesn't remove original status from feed"""
|
||||
|
@ -166,7 +166,7 @@ class Activitystreams(TestCase):
|
|||
user=self.remote_user,
|
||||
)
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||
) as mock:
|
||||
activitystreams.handle_boost_task(boost.id)
|
||||
|
||||
|
@ -174,10 +174,10 @@ class Activitystreams(TestCase):
|
|||
self.assertEqual(mock.call_count, 1)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertEqual(call_args[1]["stores"], [])
|
||||
self.assertEqual(call_args[0][1], [])
|
||||
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_boost_to_following_timeline(self, *_):
|
||||
"""add a boost and deduplicate the boosted status on the timeline"""
|
||||
|
@ -189,17 +189,17 @@ class Activitystreams(TestCase):
|
|||
user=self.another_user,
|
||||
)
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||
) as mock:
|
||||
activitystreams.handle_boost_task(boost.id)
|
||||
self.assertTrue(mock.called)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertTrue(f"{self.another_user.id}-home" in call_args[1]["stores"])
|
||||
self.assertTrue(f"{self.local_user.id}-home" in call_args[1]["stores"])
|
||||
self.assertTrue(f"{self.another_user.id}-home" in call_args[0][1])
|
||||
self.assertTrue(f"{self.local_user.id}-home" in call_args[0][1])
|
||||
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||
def test_boost_to_same_timeline(self, *_):
|
||||
"""add a boost and deduplicate the boosted status on the timeline"""
|
||||
|
@ -210,10 +210,10 @@ class Activitystreams(TestCase):
|
|||
user=self.local_user,
|
||||
)
|
||||
with patch(
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||
) as mock:
|
||||
activitystreams.handle_boost_task(boost.id)
|
||||
self.assertTrue(mock.called)
|
||||
call_args = mock.call_args
|
||||
self.assertEqual(call_args[0][0], status)
|
||||
self.assertEqual(call_args[1]["stores"], [f"{self.local_user.id}-home"])
|
||||
self.assertEqual(call_args[0][1], [f"{self.local_user.id}-home"])
|
||||
|
|
|
@ -59,7 +59,7 @@ class Activitystreams(TestCase):
|
|||
def test_remove_list_task(self, *_):
|
||||
"""remove a list from all streams"""
|
||||
with patch(
|
||||
"bookwyrm.lists_stream.ListsStream.remove_object_from_related_stores"
|
||||
"bookwyrm.lists_stream.ListsStream.remove_object_from_stores"
|
||||
) as mock:
|
||||
lists_stream.remove_list_task(self.list.id)
|
||||
self.assertEqual(mock.call_count, 1)
|
||||
|
|
Loading…
Reference in a new issue