From 825378d83a27f6c6322893914e4b3f9f4f77b125 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Wed, 29 Aug 2012 18:44:43 -0700 Subject: [PATCH] Fixing ghost unreads by accounting for the implicit score of 1 in unsorted sets in redis when intersected with a sorted set. Doh! --- apps/reader/models.py | 5 +++-- apps/social/models.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/reader/models.py b/apps/reader/models.py index 30b3eeb72..fe3bcdf22 100644 --- a/apps/reader/models.py +++ b/apps/reader/models.py @@ -128,7 +128,7 @@ class UserSubscription(models.Model): if order == 'oldest': byscorefunc = r.zrangebyscore if read_filter == 'unread' or True: - min_score = int(time.mktime(self.mark_read_date.timetuple())) + min_score = int(time.mktime(self.mark_read_date.timetuple())) + 1 else: now = datetime.datetime.now() two_weeks_ago = now - datetime.timedelta(days=settings.DAYS_OF_UNREAD) @@ -137,7 +137,8 @@ class UserSubscription(models.Model): else: byscorefunc = r.zrevrangebyscore min_score = current_time - max_score = int(time.mktime(self.mark_read_date.timetuple())) + # +1 for the intersection b/w zF and F, which carries an implicit score of 1. + max_score = int(time.mktime(self.mark_read_date.timetuple())) + 1 if settings.DEBUG: print " ---> Unread all stories: %s" % r.zrevrange(unread_ranked_stories_key, 0, -1) diff --git a/apps/social/models.py b/apps/social/models.py index 5edb7e168..2c92f6e83 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -712,7 +712,7 @@ class MSocialSubscription(mongo.Document): r.zinterstore(unread_ranked_stories_key, [sorted_stories_key, unread_stories_key]) current_time = int(time.time() + 60*60*24) - mark_read_time = int(time.mktime(self.mark_read_date.timetuple())) + mark_read_time = int(time.mktime(self.mark_read_date.timetuple())) + 1 if order == 'oldest': byscorefunc = r.zrangebyscore min_score = mark_read_time