mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00
Moving to a naive story tag counter. Can schedule re-counts if necessary.
This commit is contained in:
parent
db2ffb0f87
commit
9173bee736
3 changed files with 50 additions and 3 deletions
|
@ -1808,6 +1808,7 @@ def _mark_story_as_starred(request):
|
|||
params = dict(story_guid=story.story_guid, user_id=request.user.pk)
|
||||
starred_story = MStarredStory.objects(**params).limit(1)
|
||||
created = False
|
||||
removed_user_tags = []
|
||||
if not starred_story:
|
||||
params.update(story_values)
|
||||
starred_story = MStarredStory.objects.create(**params)
|
||||
|
@ -1816,12 +1817,37 @@ def _mark_story_as_starred(request):
|
|||
story_title=story.story_title,
|
||||
story_feed_id=feed_id,
|
||||
story_id=starred_story.story_guid)
|
||||
new_user_tags = user_tags
|
||||
else:
|
||||
starred_story = starred_story[0]
|
||||
new_user_tags = list(set(user_tags) - set(starred_story.user_tags or []))
|
||||
removed_user_tags = list(set(starred_story.user_tags or []) - set(user_tags))
|
||||
starred_story.user_tags = user_tags
|
||||
starred_story.save()
|
||||
|
||||
MStarredStoryCounts.count_tags_for_user(request.user.pk)
|
||||
for tag in new_user_tags:
|
||||
try:
|
||||
story_count = MStarredStoryCounts.objects.get(user_id=request.user.pk,
|
||||
tag=tag)
|
||||
except MStarredStoryCounts.DoesNotExist:
|
||||
story_count = MStarredStoryCounts.objects.create(user_id=request.user.pk,
|
||||
tag=tag)
|
||||
if not story_count.count:
|
||||
story_count.count = 0
|
||||
story_count.count += 1
|
||||
story_count.save()
|
||||
for tag in removed_user_tags:
|
||||
try:
|
||||
story_count = MStarredStoryCounts.objects.get(user_id=request.user.pk,
|
||||
tag=tag)
|
||||
story_count.count -= 1
|
||||
story_count.save()
|
||||
if story_count.count <= 0:
|
||||
story_count.delete()
|
||||
except MStarredStoryCounts.DoesNotExist:
|
||||
pass
|
||||
|
||||
# MStarredStoryCounts.schedule_count_tags_for_user(request.user.pk)
|
||||
starred_counts = MStarredStoryCounts.user_counts(request.user.pk)
|
||||
|
||||
if created:
|
||||
|
@ -1857,6 +1883,7 @@ def _mark_story_as_unstarred(request):
|
|||
if starred_story:
|
||||
starred_story = starred_story[0]
|
||||
logging.user(request, "~FCUnstarring: ~SB%s" % (starred_story.story_title[:50]))
|
||||
user_tags = starred_story.user_tags
|
||||
MActivity.remove_starred_story(user_id=request.user.pk,
|
||||
story_feed_id=starred_story.story_feed_id,
|
||||
story_id=starred_story.story_guid)
|
||||
|
@ -1865,7 +1892,17 @@ def _mark_story_as_unstarred(request):
|
|||
starred_story.save()
|
||||
except NotUniqueError:
|
||||
starred_story.delete()
|
||||
MStarredStoryCounts.count_tags_for_user(request.user.pk)
|
||||
for tag in user_tags:
|
||||
try:
|
||||
story_count = MStarredStoryCounts.objects.get(user_id=request.user.pk,
|
||||
tag=tag)
|
||||
story_count.count -= 1
|
||||
story_count.save()
|
||||
if story_count.count <= 0:
|
||||
story_count.delete()
|
||||
except MStarredStoryCounts.DoesNotExist:
|
||||
pass
|
||||
# MStarredStoryCounts.schedule_count_tags_for_user(request.user.pk)
|
||||
starred_counts = MStarredStoryCounts.user_counts(request.user.pk)
|
||||
else:
|
||||
code = -1
|
||||
|
|
|
@ -27,7 +27,7 @@ from django.template.defaultfilters import slugify
|
|||
from mongoengine.queryset import OperationError, Q, NotUniqueError
|
||||
from mongoengine.base import ValidationError
|
||||
from vendor.timezones.utilities import localtime_for_timezone
|
||||
from apps.rss_feeds.tasks import UpdateFeeds, PushFeeds
|
||||
from apps.rss_feeds.tasks import UpdateFeeds, PushFeeds, ScheduleCountTagsForUser
|
||||
from apps.rss_feeds.text_importer import TextImporter
|
||||
from apps.search.models import SearchStory, SearchFeed
|
||||
from apps.statistics.rstats import RStats
|
||||
|
@ -2208,6 +2208,10 @@ class MStarredStoryCounts(mongo.Document):
|
|||
|
||||
return counts
|
||||
|
||||
@classmethod
|
||||
def schedule_count_tags_for_user(cls, user_id):
|
||||
ScheduleCountTagsForUser.apply_async(kwargs=dict(user_id=user_id))
|
||||
|
||||
@classmethod
|
||||
def count_tags_for_user(cls, user_id):
|
||||
all_tags = MStarredStory.objects(user_id=user_id,
|
||||
|
|
|
@ -216,3 +216,9 @@ class SchedulePremiumSetup(Task):
|
|||
|
||||
Feed.setup_feeds_for_premium_subscribers(feed_ids)
|
||||
|
||||
class ScheduleCountTagsForUser(Task):
|
||||
|
||||
def run(self, user_id):
|
||||
from apps.rss_feeds.models import MStarredStory
|
||||
|
||||
MStarredStory.count_tags_for_user(user_id)
|
||||
|
|
Loading…
Add table
Reference in a new issue