Skip to content

Commit

Permalink
Correctly counting shared stories by using social sub's mark as read …
Browse files Browse the repository at this point in the history
…date. Matches individual blurblogs unread counts and unread stories with All Shared Stories.
  • Loading branch information
samuelclay committed Jan 11, 2017
1 parent 75837d0 commit b548e9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/social/models.py
Expand Up @@ -923,7 +923,7 @@ def story_hashes(cls, user_id, relative_user_id, subscription_user_ids=None, soc

read_dates = dict()
for us in socialsubs:
read_dates[us.subscription_user_id] = int(max(us.mark_read_date, cutoff_date).strftime('%s'))
read_dates[us.subscription_user_id] = int(max(us.mark_read_date, cutoff_date).strftime('%s'))

for sub_user_id_group in chunks(subscription_user_ids, 20):
pipeline = r.pipeline()
Expand Down Expand Up @@ -1277,7 +1277,7 @@ def calculate_feed_scores(self, force=False, silent=False):
self.mark_read_date = date_delta

unread_story_hashes = self.get_stories(read_filter='unread', limit=500, hashes_only=True,
cutoff_date=user_profile.unread_cutoff)
cutoff_date=date_delta)
stories_db = MSharedStory.objects(user_id=self.subscription_user_id,
story_hash__in=unread_story_hashes)
story_feed_ids = set()
Expand Down
5 changes: 3 additions & 2 deletions apps/social/views.py
Expand Up @@ -70,7 +70,8 @@ def load_social_stories(request, user_id, username=None):
stories = []
message = "You must be a premium subscriber to search."
elif socialsub and (read_filter == 'unread' or order == 'oldest'):
story_hashes = socialsub.get_stories(order=order, read_filter=read_filter, offset=offset, limit=limit, cutoff_date=user.profile.unread_cutoff)
cutoff_date = max(socialsub.mark_read_date, user.profile.unread_cutoff)
story_hashes = socialsub.get_stories(order=order, read_filter=read_filter, offset=offset, limit=limit, cutoff_date=cutoff_date)
story_date_order = "%sshared_date" % ('' if order == 'oldest' else '-')
if story_hashes:
mstories = MSharedStory.objects(user_id=social_user.pk,
Expand All @@ -80,7 +81,7 @@ def load_social_stories(request, user_id, username=None):
mstories = MSharedStory.objects(user_id=social_user.pk).order_by('-shared_date')[offset:offset+limit]
stories = Feed.format_stories(mstories)

if not stories:
if not stories or False: # False is to force a recount even if 0 stories
return dict(stories=[], message=message)

stories, user_profiles = MSharedStory.stories_with_comments_and_profiles(stories, user.pk, check_all=True)
Expand Down

0 comments on commit b548e9c

Please sign in to comment.