Counting starred stories if no count exists.

This commit is contained in:
Samuel Clay 2013-09-09 18:49:21 -07:00
parent 26b2b802e1
commit 9147543001
2 changed files with 9 additions and 6 deletions

View file

@ -258,8 +258,6 @@ def load_feeds(request):
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds))
starred_counts, starred_count = MStarredStoryCounts.user_counts(user.pk, include_total=True)
if not starred_count and len(starred_counts):
starred_count = MStarredStory.objects(user_id=user.pk).count()
social_params = {
'user_id': user.pk,

View file

@ -2051,10 +2051,14 @@ class MStarredStoryCounts(mongo.Document):
}
@classmethod
def user_counts(cls, user_id, include_total=False):
def user_counts(cls, user_id, include_total=False, try_counting=True):
counts = cls.objects.filter(user_id=user_id).only('tag', 'count')
counts = [{'tag': c.tag, 'count': c.count} for c in counts]
if counts == [] and try_counting:
cls.count_tags_for_user(user_id)
return cls.user_counts(user_id, include_total=include_total, try_counting=False)
if include_total:
for c in counts:
if c['tag'] == "":
@ -2076,8 +2080,9 @@ class MStarredStoryCounts(mongo.Document):
cls.objects.create(user_id=user_id, tag=tag, count=count)
total_stories_count = MStarredStory.objects(user_id=user_id).count()
cls.objects(user_id=user_id, tag="", count=total_stories_count)
cls.objects.create(user_id=user_id, tag="", count=total_stories_count)
return dict(total=total_stories_count, tags=user_tags)
class MFetchHistory(mongo.Document):
feed_id = mongo.IntField(unique=True)