mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-16 05:06:32 +00:00
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,
|
local=True,
|
||||||
).exclude(following=obj)
|
).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 """
|
""" update all the instances of this user with new ranks """
|
||||||
pipeline = r.pipeline()
|
pipeline = r.pipeline()
|
||||||
for store_user in self.get_users_for_object(obj):
|
for store_user in self.get_users_for_object(obj):
|
||||||
|
@ -60,7 +60,7 @@ class SuggestedUsers(RedisStore):
|
||||||
pipeline.zadd(
|
pipeline.zadd(
|
||||||
self.store_id(store_user),
|
self.store_id(store_user),
|
||||||
self.get_value(annotated_user),
|
self.get_value(annotated_user),
|
||||||
xx=True
|
xx=update_only
|
||||||
)
|
)
|
||||||
pipeline.execute()
|
pipeline.execute()
|
||||||
|
|
||||||
|
@ -146,13 +146,14 @@ def add_or_remove_on_discoverability_change(
|
||||||
sender, instance, created, raw, using, update_fields, **kwargs
|
sender, instance, created, raw, using, update_fields, **kwargs
|
||||||
):
|
):
|
||||||
""" make a user (un)discoverable """
|
""" make a user (un)discoverable """
|
||||||
if not update_fields or not "discoverable" in update_fields:
|
|
||||||
return
|
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
suggested_users.rerank_user_suggestions(instance)
|
suggested_users.rerank_user_suggestions(instance)
|
||||||
|
|
||||||
|
if not created and (not update_fields or not "discoverable" in update_fields):
|
||||||
|
return
|
||||||
|
|
||||||
if instance.discoverable:
|
if instance.discoverable:
|
||||||
suggested_users.rerank_obj(instance)
|
suggested_users.rerank_obj(instance, update_only=False)
|
||||||
|
|
||||||
elif not created and not instance.discoverable:
|
elif not created and not instance.discoverable:
|
||||||
suggested_users.remove_object_from_related_stores(instance)
|
suggested_users.remove_object_from_related_stores(instance)
|
||||||
|
|
|
@ -181,7 +181,11 @@ def save_user_form(form):
|
||||||
extension = form.files["avatar"].name.split(".")[-1]
|
extension = form.files["avatar"].name.split(".")[-1]
|
||||||
filename = "%s.%s" % (uuid4(), extension)
|
filename = "%s.%s" % (uuid4(), extension)
|
||||||
user.avatar.save(filename, image, save=False)
|
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
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue