Attempting to fix the unread count bug in socialsubs.

This commit is contained in:
Samuel Clay 2012-08-10 10:35:11 -07:00
parent 5c819b01b3
commit 7bdf4aa64e
2 changed files with 10 additions and 6 deletions

View file

@ -317,6 +317,9 @@ def load_feeds_flat(request):
social_feeds = MSocialSubscription.feeds(**social_params)
social_profile = MSocialProfile.profile(user.pk)
logging.user(request, "~FBLoading ~SB%s~SN/~SB%s~SN feeds/socials ~FMflat~FB. %s" % (
len(feeds.keys()), len(social_feeds), '~SBUpdating counts.' if update_counts else ''))
data = {
"flat_folders": flat_folders,
"feeds": feeds,

View file

@ -834,17 +834,18 @@ class MSocialSubscription(mongo.Document):
UNREAD_CUTOFF = datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD)
# Use the latest story to get last read time.
if MSharedStory.objects(user_id=self.subscription_user_id).first():
latest_story_date = MSharedStory.objects(user_id=self.subscription_user_id)\
.order_by('-shared_date').only('shared_date')[0]['shared_date']\
+ datetime.timedelta(seconds=1)
latest_shared_story = MSharedStory.objects(user_id=self.subscription_user_id,
shared_date__gte=UNREAD_CUTOFF
).order_by('shared_date').only('shared_date').first()
if latest_shared_story:
latest_story_date = latest_shared_story['shared_date'] + datetime.timedelta(seconds=1)
self.last_read_date = latest_story_date
self.mark_read_date = UNREAD_CUTOFF
self.unread_count_negative = 0
self.unread_count_positive = 0
self.unread_count_neutral = 0
self.unread_count_updated = latest_story_date
self.unread_count_updated = datetime.datetime.utcnow()
self.oldest_unread_story_date = latest_story_date
self.needs_unread_recalc = False