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 stream in streams.values():
|
||||||
for status in statuses:
|
for status in statuses:
|
||||||
stream.remove_object_from_related_stores(
|
stream.remove_object_from_stores(
|
||||||
status, stores=stream.get_stores_for_object(status)
|
status, stream.get_stores_for_object(status)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -568,9 +568,9 @@ def handle_boost_task(boost_id):
|
||||||
for stream in streams.values():
|
for stream in streams.values():
|
||||||
# people who should see the boost (not people who see the original status)
|
# people who should see the boost (not people who see the original status)
|
||||||
audience = stream.get_stores_for_object(instance)
|
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:
|
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):
|
def get_status_type(status):
|
||||||
|
|
|
@ -232,7 +232,7 @@ def remove_list_task(list_id, re_add=False):
|
||||||
|
|
||||||
# delete for every store
|
# delete for every store
|
||||||
stores = [ListsStream().stream_id(idx) for idx in stores]
|
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:
|
if re_add:
|
||||||
add_list_task.delay(list_id)
|
add_list_task.delay(list_id)
|
||||||
|
|
|
@ -32,14 +32,14 @@ class RedisStore(ABC):
|
||||||
# and go!
|
# and go!
|
||||||
return pipeline.execute()
|
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"""
|
"""remove an object from all stores"""
|
||||||
# if the stoers are provided, the object can just be an id
|
# if the stoers are provided, the object can just be an id
|
||||||
if stores and isinstance(obj, int):
|
if stores and isinstance(obj, int):
|
||||||
obj_id = obj
|
obj_id = obj
|
||||||
else:
|
else:
|
||||||
obj_id = obj.id
|
obj_id = obj.id
|
||||||
stores = self.get_stores_for_object(obj) if stores is None else stores
|
|
||||||
pipeline = r.pipeline()
|
pipeline = r.pipeline()
|
||||||
for store in stores:
|
for store in stores:
|
||||||
pipeline.zrem(store, -1, obj_id)
|
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):
|
def remove_user_task(user_id):
|
||||||
"""do the hard work in celery"""
|
"""do the hard work in celery"""
|
||||||
user = models.User.objects.get(id=user_id)
|
user = models.User.objects.get(id=user_id)
|
||||||
suggested_users.remove_object_from_related_stores(
|
suggested_users.remove_object_from_stores(
|
||||||
user, stores=suggested_users.get_stores_for_object(user)
|
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):
|
def bulk_remove_instance_task(instance_id):
|
||||||
"""remove a bunch of users from recs"""
|
"""remove a bunch of users from recs"""
|
||||||
for user in models.User.objects.filter(federated_server__id=instance_id):
|
for user in models.User.objects.filter(federated_server__id=instance_id):
|
||||||
suggested_users.remove_object_from_related_stores(
|
suggested_users.remove_object_from_stores(
|
||||||
user, stores=suggested_users.get_stores_for_object(user)
|
user, suggested_users.get_stores_for_object(user)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Activitystreams(TestCase):
|
||||||
def test_remove_status_task(self):
|
def test_remove_status_task(self):
|
||||||
"""remove a status from all streams"""
|
"""remove a status from all streams"""
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.activitystreams.ActivityStream.remove_object_from_related_stores"
|
"bookwyrm.activitystreams.ActivityStream.remove_object_from_stores"
|
||||||
) as mock:
|
) as mock:
|
||||||
activitystreams.remove_status_task(self.status.id)
|
activitystreams.remove_status_task(self.status.id)
|
||||||
self.assertEqual(mock.call_count, 3)
|
self.assertEqual(mock.call_count, 3)
|
||||||
|
@ -132,8 +132,8 @@ class Activitystreams(TestCase):
|
||||||
self.assertEqual(args[0], self.local_user)
|
self.assertEqual(args[0], self.local_user)
|
||||||
self.assertEqual(args[1], self.another_user)
|
self.assertEqual(args[1], self.another_user)
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.LocalStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||||
def test_boost_to_another_timeline(self, *_):
|
def test_boost_to_another_timeline(self, *_):
|
||||||
"""boost from a non-follower doesn't remove original status from feed"""
|
"""boost from a non-follower doesn't remove original status from feed"""
|
||||||
|
@ -144,7 +144,7 @@ class Activitystreams(TestCase):
|
||||||
user=self.another_user,
|
user=self.another_user,
|
||||||
)
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||||
) as mock:
|
) as mock:
|
||||||
activitystreams.handle_boost_task(boost.id)
|
activitystreams.handle_boost_task(boost.id)
|
||||||
|
|
||||||
|
@ -152,10 +152,10 @@ class Activitystreams(TestCase):
|
||||||
self.assertEqual(mock.call_count, 1)
|
self.assertEqual(mock.call_count, 1)
|
||||||
call_args = mock.call_args
|
call_args = mock.call_args
|
||||||
self.assertEqual(call_args[0][0], status)
|
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.LocalStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||||
def test_boost_to_another_timeline_remote(self, *_):
|
def test_boost_to_another_timeline_remote(self, *_):
|
||||||
"""boost from a remote non-follower doesn't remove original status from feed"""
|
"""boost from a remote non-follower doesn't remove original status from feed"""
|
||||||
|
@ -166,7 +166,7 @@ class Activitystreams(TestCase):
|
||||||
user=self.remote_user,
|
user=self.remote_user,
|
||||||
)
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||||
) as mock:
|
) as mock:
|
||||||
activitystreams.handle_boost_task(boost.id)
|
activitystreams.handle_boost_task(boost.id)
|
||||||
|
|
||||||
|
@ -174,10 +174,10 @@ class Activitystreams(TestCase):
|
||||||
self.assertEqual(mock.call_count, 1)
|
self.assertEqual(mock.call_count, 1)
|
||||||
call_args = mock.call_args
|
call_args = mock.call_args
|
||||||
self.assertEqual(call_args[0][0], status)
|
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.LocalStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||||
def test_boost_to_following_timeline(self, *_):
|
def test_boost_to_following_timeline(self, *_):
|
||||||
"""add a boost and deduplicate the boosted status on the timeline"""
|
"""add a boost and deduplicate the boosted status on the timeline"""
|
||||||
|
@ -189,17 +189,17 @@ class Activitystreams(TestCase):
|
||||||
user=self.another_user,
|
user=self.another_user,
|
||||||
)
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||||
) as mock:
|
) as mock:
|
||||||
activitystreams.handle_boost_task(boost.id)
|
activitystreams.handle_boost_task(boost.id)
|
||||||
self.assertTrue(mock.called)
|
self.assertTrue(mock.called)
|
||||||
call_args = mock.call_args
|
call_args = mock.call_args
|
||||||
self.assertEqual(call_args[0][0], status)
|
self.assertEqual(call_args[0][0], status)
|
||||||
self.assertTrue(f"{self.another_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[1]["stores"])
|
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.LocalStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_related_stores")
|
@patch("bookwyrm.activitystreams.BooksStream.remove_object_from_stores")
|
||||||
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async")
|
||||||
def test_boost_to_same_timeline(self, *_):
|
def test_boost_to_same_timeline(self, *_):
|
||||||
"""add a boost and deduplicate the boosted status on the timeline"""
|
"""add a boost and deduplicate the boosted status on the timeline"""
|
||||||
|
@ -210,10 +210,10 @@ class Activitystreams(TestCase):
|
||||||
user=self.local_user,
|
user=self.local_user,
|
||||||
)
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.activitystreams.HomeStream.remove_object_from_related_stores"
|
"bookwyrm.activitystreams.HomeStream.remove_object_from_stores"
|
||||||
) as mock:
|
) as mock:
|
||||||
activitystreams.handle_boost_task(boost.id)
|
activitystreams.handle_boost_task(boost.id)
|
||||||
self.assertTrue(mock.called)
|
self.assertTrue(mock.called)
|
||||||
call_args = mock.call_args
|
call_args = mock.call_args
|
||||||
self.assertEqual(call_args[0][0], status)
|
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, *_):
|
def test_remove_list_task(self, *_):
|
||||||
"""remove a list from all streams"""
|
"""remove a list from all streams"""
|
||||||
with patch(
|
with patch(
|
||||||
"bookwyrm.lists_stream.ListsStream.remove_object_from_related_stores"
|
"bookwyrm.lists_stream.ListsStream.remove_object_from_stores"
|
||||||
) as mock:
|
) as mock:
|
||||||
lists_stream.remove_list_task(self.list.id)
|
lists_stream.remove_list_task(self.list.id)
|
||||||
self.assertEqual(mock.call_count, 1)
|
self.assertEqual(mock.call_count, 1)
|
||||||
|
|
Loading…
Reference in a new issue