forked from mirrors/bookwyrm
Only re-rank on bookwyrm instances
This commit is contained in:
parent
d3b3dd6d99
commit
88a65b0b88
2 changed files with 13 additions and 10 deletions
|
@ -28,7 +28,7 @@ class FederatedServer(BookWyrmModel):
|
|||
def block(self):
|
||||
"""block a server"""
|
||||
self.status = "blocked"
|
||||
self.save(update_fields="status")
|
||||
self.save(update_fields=["status"])
|
||||
|
||||
# deactivate all associated users
|
||||
self.user_set.filter(is_active=True).update(
|
||||
|
@ -45,7 +45,7 @@ class FederatedServer(BookWyrmModel):
|
|||
def unblock(self):
|
||||
"""unblock a server"""
|
||||
self.status = "federated"
|
||||
self.save(update_fields="status")
|
||||
self.save(update_fields=["status"])
|
||||
|
||||
self.user_set.filter(deactivation_reason="domain_block").update(
|
||||
is_active=True, deactivation_reason=None
|
||||
|
|
|
@ -210,14 +210,17 @@ def update_user(sender, instance, created, update_fields=None, **kwargs):
|
|||
@receiver(signals.post_save, sender=models.FederatedServer)
|
||||
def domain_level_update(sender, instance, created, update_fields=None, **kwargs):
|
||||
"""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
|
||||
|
||||
userset = instance.user_set.values_list("id", flat=True)
|
||||
if instance.status == "blocked":
|
||||
bulk_remove_users_task.delay(userset)
|
||||
bulk_remove_instance_task.delay(instance.id)
|
||||
return
|
||||
bulk_add_users_task.delay(userset)
|
||||
bulk_add_instance_task.delay(instance.id)
|
||||
|
||||
|
||||
# ------------------- TASKS
|
||||
|
@ -251,14 +254,14 @@ def remove_suggestion_task(user_id, suggested_user_id):
|
|||
|
||||
|
||||
@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"""
|
||||
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)
|
||||
|
||||
|
||||
@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"""
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue