Fixes inactive or mastodon users showing up in suggestions
They shouldn't be there, but just to be safe
This commit is contained in:
parent
e06e507c8d
commit
2e2ee72333
|
@ -85,10 +85,12 @@ class SuggestedUsers(RedisStore):
|
||||||
values = self.get_store(self.store_id(user), withscores=True)
|
values = self.get_store(self.store_id(user), withscores=True)
|
||||||
results = []
|
results = []
|
||||||
# annotate users with mutuals and shared book counts
|
# annotate users with mutuals and shared book counts
|
||||||
for user_id, rank in values[:5]:
|
for user_id, rank in values:
|
||||||
counts = self.get_counts_from_rank(rank)
|
counts = self.get_counts_from_rank(rank)
|
||||||
try:
|
try:
|
||||||
user = models.User.objects.get(id=user_id)
|
user = models.User.objects.get(
|
||||||
|
id=user_id, is_active=True, bookwyrm_user=True
|
||||||
|
)
|
||||||
except models.User.DoesNotExist as err:
|
except models.User.DoesNotExist as err:
|
||||||
# if this happens, the suggestions are janked way up
|
# if this happens, the suggestions are janked way up
|
||||||
logger.exception(err)
|
logger.exception(err)
|
||||||
|
@ -96,6 +98,8 @@ class SuggestedUsers(RedisStore):
|
||||||
user.mutuals = counts["mutuals"]
|
user.mutuals = counts["mutuals"]
|
||||||
# user.shared_books = counts["shared_books"]
|
# user.shared_books = counts["shared_books"]
|
||||||
results.append(user)
|
results.append(user)
|
||||||
|
if len(results) >= 5:
|
||||||
|
break
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,14 +183,16 @@ def update_suggestions_on_unfollow(sender, instance, **kwargs):
|
||||||
|
|
||||||
@receiver(signals.post_save, sender=models.User)
|
@receiver(signals.post_save, sender=models.User)
|
||||||
# pylint: disable=unused-argument, too-many-arguments
|
# pylint: disable=unused-argument, too-many-arguments
|
||||||
def updated_user(sender, instance, created, update_fields=None, **kwargs):
|
def update_user(sender, instance, created, update_fields=None, **kwargs):
|
||||||
"""an updated user, neat"""
|
"""an updated user, neat"""
|
||||||
# a new user is found, create suggestions for them
|
# a new user is found, create suggestions for them
|
||||||
if created and instance.local:
|
if created and instance.local:
|
||||||
rerank_suggestions_task.delay(instance.id)
|
rerank_suggestions_task.delay(instance.id)
|
||||||
|
|
||||||
# we know what fields were updated and discoverability didn't change
|
# we know what fields were updated and discoverability didn't change
|
||||||
if update_fields and not "discoverable" in update_fields:
|
if not instance.bookwyrm_user or (
|
||||||
|
update_fields and not "discoverable" in update_fields
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
# deleted the user
|
# deleted the user
|
||||||
|
@ -201,6 +207,9 @@ def updated_user(sender, instance, created, update_fields=None, **kwargs):
|
||||||
remove_user_task.delay(instance.id)
|
remove_user_task.delay(instance.id)
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------- TASKS
|
||||||
|
|
||||||
|
|
||||||
@app.task(queue="low_priority")
|
@app.task(queue="low_priority")
|
||||||
def rerank_suggestions_task(user_id):
|
def rerank_suggestions_task(user_id):
|
||||||
"""do the hard work in celery"""
|
"""do the hard work in celery"""
|
||||||
|
|
Loading…
Reference in New Issue