forked from mirrors/bookwyrm
Removes stale data before doing repopulation
This probably is only an issue when there are very few users, like my test instance
This commit is contained in:
parent
01334b6613
commit
df9787dd7a
2 changed files with 14 additions and 1 deletions
|
@ -65,6 +65,10 @@ class RedisStore(ABC):
|
||||||
pipeline = r.pipeline()
|
pipeline = r.pipeline()
|
||||||
queryset = self.get_objects_for_store(store)
|
queryset = self.get_objects_for_store(store)
|
||||||
|
|
||||||
|
# first, remove everything currently in it
|
||||||
|
pipeline.delete(store)
|
||||||
|
|
||||||
|
# now, add everything back
|
||||||
for obj in queryset[: self.max_length]:
|
for obj in queryset[: self.max_length]:
|
||||||
pipeline.zadd(store, self.get_value(obj))
|
pipeline.zadd(store, self.get_value(obj))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
""" store recommended follows in redis """
|
""" store recommended follows in redis """
|
||||||
import math
|
import math
|
||||||
|
import logging
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.db.models import signals, Count, Q
|
from django.db.models import signals, Count, Q
|
||||||
|
|
||||||
|
@ -8,6 +9,9 @@ from bookwyrm.redis_store import RedisStore, r
|
||||||
from bookwyrm.tasks import app
|
from bookwyrm.tasks import app
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SuggestedUsers(RedisStore):
|
class SuggestedUsers(RedisStore):
|
||||||
"""suggested users for a user"""
|
"""suggested users for a user"""
|
||||||
|
|
||||||
|
@ -84,7 +88,12 @@ class SuggestedUsers(RedisStore):
|
||||||
# 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[:5]:
|
||||||
counts = self.get_counts_from_rank(rank)
|
counts = self.get_counts_from_rank(rank)
|
||||||
user = models.User.objects.get(id=user_id)
|
try:
|
||||||
|
user = models.User.objects.get(id=user_id)
|
||||||
|
except models.User.DoesNotExist as err:
|
||||||
|
# if this happens, the suggestions are janked way up
|
||||||
|
logger.exception(err)
|
||||||
|
continue
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue