forked from mirrors/bookwyrm
Updates logic for new and newly discoverable users
This commit is contained in:
parent
9880bdc75b
commit
4fb85ced5f
2 changed files with 12 additions and 7 deletions
|
@ -48,7 +48,7 @@ class SuggestedUsers(RedisStore):
|
|||
local=True,
|
||||
).exclude(following=obj)
|
||||
|
||||
def rerank_obj(self, obj):
|
||||
def rerank_obj(self, obj, update_only=True):
|
||||
""" update all the instances of this user with new ranks """
|
||||
pipeline = r.pipeline()
|
||||
for store_user in self.get_users_for_object(obj):
|
||||
|
@ -60,7 +60,7 @@ class SuggestedUsers(RedisStore):
|
|||
pipeline.zadd(
|
||||
self.store_id(store_user),
|
||||
self.get_value(annotated_user),
|
||||
xx=True
|
||||
xx=update_only
|
||||
)
|
||||
pipeline.execute()
|
||||
|
||||
|
@ -146,13 +146,14 @@ def add_or_remove_on_discoverability_change(
|
|||
sender, instance, created, raw, using, update_fields, **kwargs
|
||||
):
|
||||
""" make a user (un)discoverable """
|
||||
if not update_fields or not "discoverable" in update_fields:
|
||||
return
|
||||
|
||||
if created:
|
||||
suggested_users.rerank_user_suggestions(instance)
|
||||
|
||||
if not created and (not update_fields or not "discoverable" in update_fields):
|
||||
return
|
||||
|
||||
if instance.discoverable:
|
||||
suggested_users.rerank_obj(instance)
|
||||
suggested_users.rerank_obj(instance, update_only=False)
|
||||
|
||||
elif not created and not instance.discoverable:
|
||||
suggested_users.remove_object_from_related_stores(instance)
|
||||
|
|
|
@ -181,7 +181,11 @@ def save_user_form(form):
|
|||
extension = form.files["avatar"].name.split(".")[-1]
|
||||
filename = "%s.%s" % (uuid4(), extension)
|
||||
user.avatar.save(filename, image, save=False)
|
||||
user.save()
|
||||
|
||||
updated_fields = None
|
||||
if form.initial["discoverable"] != form.cleaned_data["discoverable"]:
|
||||
updated_fields = ["discoverable"]
|
||||
user.save(updated_fields=updated_fields)
|
||||
return user
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue