diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 49458a2e0..b87ffd7d1 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -243,7 +243,6 @@ class User(OrderedCollectionPageMixin, AbstractUser): # generate a username that uses the domain (webfinger format) actor_parts = urlparse(self.remote_id) self.username = "%s@%s" % (self.username, actor_parts.netloc) - super().save(*args, **kwargs) # this user already exists, no need to populate fields if not created: @@ -276,7 +275,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): self.key_pair = KeyPair.objects.create( remote_id="%s/#main-key" % self.remote_id ) - self.save(broadcast=False) + self.save(broadcast=False, update_fields=["key_pair"]) shelves = [ { diff --git a/bookwyrm/suggested_users.py b/bookwyrm/suggested_users.py index e588bc9e8..b48b4e74a 100644 --- a/bookwyrm/suggested_users.py +++ b/bookwyrm/suggested_users.py @@ -178,12 +178,15 @@ def update_rank_on_shelving(sender, instance, *args, **kwargs): @receiver(signals.post_save, sender=models.User) # pylint: disable=unused-argument, too-many-arguments -def add_new_user(sender, instance, created, **kwargs): +def add_new_user(sender, instance, created, update_fields=None, **kwargs): """a new user, wow how cool""" # a new user is found, create suggestions for them if created and instance.local: rerank_suggestions_task.delay(instance.id) + if update_fields and not "discoverable" in update_fields: + return + # this happens on every save, not just when discoverability changes, annoyingly if instance.discoverable: rerank_user_task.delay(instance.id, update_only=False) diff --git a/bookwyrm/tests/test_activitystreams.py b/bookwyrm/tests/test_activitystreams.py index 0dd8ffe39..f4747971a 100644 --- a/bookwyrm/tests/test_activitystreams.py +++ b/bookwyrm/tests/test_activitystreams.py @@ -11,16 +11,17 @@ class Activitystreams(TestCase): def setUp(self): """use a test csv""" - self.local_user = models.User.objects.create_user( - "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" - ) - self.another_user = models.User.objects.create_user( - "nutria", - "nutria@nutria.nutria", - "password", - local=True, - localname="nutria", - ) + with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): + self.local_user = models.User.objects.create_user( + "mouse", "mouse@mouse.mouse", "password", local=True, localname="mouse" + ) + self.another_user = models.User.objects.create_user( + "nutria", + "nutria@nutria.nutria", + "password", + local=True, + localname="nutria", + ) with patch("bookwyrm.models.user.set_remote_server.delay"): self.remote_user = models.User.objects.create_user( "rat",