Only re-rank on bookwyrm instances

This commit is contained in:
Mouse Reeve 2021-09-08 11:47:36 -07:00
parent d3b3dd6d99
commit 88a65b0b88
2 changed files with 13 additions and 10 deletions

View file

@ -28,7 +28,7 @@ class FederatedServer(BookWyrmModel):
def block(self): def block(self):
"""block a server""" """block a server"""
self.status = "blocked" self.status = "blocked"
self.save(update_fields="status") self.save(update_fields=["status"])
# deactivate all associated users # deactivate all associated users
self.user_set.filter(is_active=True).update( self.user_set.filter(is_active=True).update(
@ -45,7 +45,7 @@ class FederatedServer(BookWyrmModel):
def unblock(self): def unblock(self):
"""unblock a server""" """unblock a server"""
self.status = "federated" self.status = "federated"
self.save(update_fields="status") self.save(update_fields=["status"])
self.user_set.filter(deactivation_reason="domain_block").update( self.user_set.filter(deactivation_reason="domain_block").update(
is_active=True, deactivation_reason=None is_active=True, deactivation_reason=None

View file

@ -210,14 +210,17 @@ def update_user(sender, instance, created, update_fields=None, **kwargs):
@receiver(signals.post_save, sender=models.FederatedServer) @receiver(signals.post_save, sender=models.FederatedServer)
def domain_level_update(sender, instance, created, update_fields=None, **kwargs): def domain_level_update(sender, instance, created, update_fields=None, **kwargs):
"""remove users on a domain block""" """remove users on a domain block"""
if not update_fields or "status" not in update_fields: if (
not update_fields
or "status" not in update_fields
or instance.application_type != "bookwyrm"
):
return return
userset = instance.user_set.values_list("id", flat=True)
if instance.status == "blocked": if instance.status == "blocked":
bulk_remove_users_task.delay(userset) bulk_remove_instance_task.delay(instance.id)
return return
bulk_add_users_task.delay(userset) bulk_add_instance_task.delay(instance.id)
# ------------------- TASKS # ------------------- TASKS
@ -251,14 +254,14 @@ def remove_suggestion_task(user_id, suggested_user_id):
@app.task(queue="low_priority") @app.task(queue="low_priority")
def bulk_remove_users_task(user_ids): 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(id__in=user_ids): for user in models.User.objects.filter(federated_server__id=instance_id):
suggested_users.remove_object_from_related_stores(user) suggested_users.remove_object_from_related_stores(user)
@app.task(queue="low_priority") @app.task(queue="low_priority")
def bulk_add_users_task(user_ids): def bulk_add_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(id__in=user_ids): for user in models.User.objects.filter(federated_server__id=instance_id):
suggested_users.rerank_obj(user, update_only=False) suggested_users.rerank_obj(user, update_only=False)