mirror of
https://github.com/viq/NewsBlur.git
synced 2025-04-13 09:38:09 +00:00
Count feed_id starred stories when totals don't match.
This commit is contained in:
parent
7f05f11f2c
commit
5e36e46049
3 changed files with 32 additions and 14 deletions
|
@ -732,7 +732,7 @@ def api_save_new_story(request):
|
||||||
}
|
}
|
||||||
story = MStarredStory.objects.create(**story_db)
|
story = MStarredStory.objects.create(**story_db)
|
||||||
logging.user(request, "~FCStarring by ~SBIFTTT~SN: ~SB%s~SN in ~SB%s" % (story_db['story_title'][:50], original_feed and original_feed))
|
logging.user(request, "~FCStarring by ~SBIFTTT~SN: ~SB%s~SN in ~SB%s" % (story_db['story_title'][:50], original_feed and original_feed))
|
||||||
MStarredStoryCounts.count_tags_for_user(user.pk)
|
MStarredStoryCounts.count_for_user(user.pk)
|
||||||
except OperationError:
|
except OperationError:
|
||||||
logging.user(request, "~FCAlready starred by ~SBIFTTT~SN: ~SB%s" % (story_db['story_title'][:50]))
|
logging.user(request, "~FCAlready starred by ~SBIFTTT~SN: ~SB%s" % (story_db['story_title'][:50]))
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -3,6 +3,7 @@ import time
|
||||||
import boto
|
import boto
|
||||||
import redis
|
import redis
|
||||||
import requests
|
import requests
|
||||||
|
import random
|
||||||
import zlib
|
import zlib
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
@ -1850,8 +1851,9 @@ def _mark_story_as_starred(request):
|
||||||
MStarredStoryCounts.adjust_count(request.user.pk, tag=tag, amount=1)
|
MStarredStoryCounts.adjust_count(request.user.pk, tag=tag, amount=1)
|
||||||
for tag in removed_user_tags:
|
for tag in removed_user_tags:
|
||||||
MStarredStoryCounts.adjust_count(request.user.pk, tag=tag, amount=-1)
|
MStarredStoryCounts.adjust_count(request.user.pk, tag=tag, amount=-1)
|
||||||
|
|
||||||
MStarredStoryCounts.schedule_count_tags_for_user(request.user.pk)
|
if random.random() < 0.01:
|
||||||
|
MStarredStoryCounts.schedule_count_tags_for_user(request.user.pk)
|
||||||
MStarredStoryCounts.count_for_user(request.user.pk, total_only=True)
|
MStarredStoryCounts.count_for_user(request.user.pk, total_only=True)
|
||||||
starred_counts = MStarredStoryCounts.user_counts(request.user.pk)
|
starred_counts = MStarredStoryCounts.user_counts(request.user.pk)
|
||||||
|
|
||||||
|
|
|
@ -2215,17 +2215,24 @@ class MStarredStoryCounts(mongo.Document):
|
||||||
for c in counts],
|
for c in counts],
|
||||||
key=lambda x: (x.get('tag', '') or '').lower())
|
key=lambda x: (x.get('tag', '') or '').lower())
|
||||||
|
|
||||||
if counts == [] and try_counting:
|
total = 0
|
||||||
|
feed_total = 0
|
||||||
|
for c in counts:
|
||||||
|
if not c['tag'] and not c['feed_id']:
|
||||||
|
total = c['count']
|
||||||
|
if c['feed_id']:
|
||||||
|
feed_total += c['count']
|
||||||
|
|
||||||
|
if try_counting and total != feed_total:
|
||||||
|
user = User.objects.get(pk=user_id)
|
||||||
|
logging.user(user, "~FC~SBCounting~SN saved stories (%s total vs. %s counted)..." %
|
||||||
|
(total, feed_total))
|
||||||
cls.count_for_user(user_id)
|
cls.count_for_user(user_id)
|
||||||
return cls.user_counts(user_id, include_total=include_total,
|
return cls.user_counts(user_id, include_total=include_total,
|
||||||
try_counting=False)
|
try_counting=False)
|
||||||
|
|
||||||
if include_total:
|
if include_total:
|
||||||
for c in counts:
|
return counts, total
|
||||||
if not c['tag'] and not c['feed_id']:
|
|
||||||
return counts, c['count']
|
|
||||||
return counts, 0
|
|
||||||
|
|
||||||
return counts
|
return counts
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -2243,8 +2250,8 @@ class MStarredStoryCounts(mongo.Document):
|
||||||
user_feeds = cls.count_feeds_for_user(user_id)
|
user_feeds = cls.count_feeds_for_user(user_id)
|
||||||
|
|
||||||
total_stories_count = MStarredStory.objects(user_id=user_id).count()
|
total_stories_count = MStarredStory.objects(user_id=user_id).count()
|
||||||
cls.objects(user_id=user_id, tag="").update_one(set__count=total_stories_count,
|
cls.objects(user_id=user_id, tag=None, feed_id=None).update_one(set__count=total_stories_count,
|
||||||
upsert=True)
|
upsert=True)
|
||||||
|
|
||||||
return dict(total=total_stories_count, tags=user_tags, feeds=user_feeds)
|
return dict(total=total_stories_count, tags=user_tags, feeds=user_feeds)
|
||||||
|
|
||||||
|
@ -2265,9 +2272,18 @@ class MStarredStoryCounts(mongo.Document):
|
||||||
@classmethod
|
@classmethod
|
||||||
def count_feeds_for_user(cls, user_id):
|
def count_feeds_for_user(cls, user_id):
|
||||||
all_feeds = MStarredStory.objects(user_id=user_id).item_frequencies('story_feed_id')
|
all_feeds = MStarredStory.objects(user_id=user_id).item_frequencies('story_feed_id')
|
||||||
user_feeds = [(k, v) for k, v in all_feeds.items() if int(v) > 0 and k]
|
user_feeds = dict([(k, v) for k, v in all_feeds.items() if v])
|
||||||
|
|
||||||
for feed_id, count in dict(user_feeds).items():
|
# Clean up None'd and 0'd feed_ids, so they can be counted against the total
|
||||||
|
if user_feeds.get(None, False):
|
||||||
|
user_feeds[0] = user_feeds.get(0, 0)
|
||||||
|
user_feeds[0] += user_feeds.get(None)
|
||||||
|
del user_feeds[None]
|
||||||
|
if user_feeds.get(0, False):
|
||||||
|
user_feeds[-1] = user_feeds.get(0, 0)
|
||||||
|
del user_feeds[0]
|
||||||
|
|
||||||
|
for feed_id, count in user_feeds.items():
|
||||||
cls.objects(user_id=user_id,
|
cls.objects(user_id=user_id,
|
||||||
feed_id=feed_id,
|
feed_id=feed_id,
|
||||||
slug="feed:%s" % feed_id).update_one(set__count=count,
|
slug="feed:%s" % feed_id).update_one(set__count=count,
|
||||||
|
|
Loading…
Add table
Reference in a new issue