Moving shared story unread recalc to background task. Will greatly speed up sharing.

This commit is contained in:
Samuel Clay 2013-03-19 16:14:19 -07:00
parent db92d3ca10
commit b2e52858ea
3 changed files with 23 additions and 8 deletions

2
.gitignore vendored
View file

@ -12,7 +12,7 @@ build/
.DS_Store
**/*.perspectivev*
data/
config/certificates/*
config/certificates
**/*.xcuserstate
UserInterfaceState.xcuserstate
UserInterfaceState\.xcuserstate

View file

@ -1,5 +1,7 @@
from bson.objectid import ObjectId
from celery.task import Task
from apps.social.models import MSharedStory, MSocialProfile, MSocialServices
from apps.social.models import MSharedStory, MSocialProfile, MSocialServices, MSocialSubscription
from django.contrib.auth.models import User
from utils import log as logging
@ -57,4 +59,19 @@ class SharePopularStories(Task):
if not shared:
shared = MSharedStory.share_popular_stories(interactive=False, days=2)
class UpdateRecalcForSubscription(Task):
def run(self, subscription_user_id, shared_story_id):
user = User.objects.get(pk=subscription_user_id)
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=subscription_user_id)
logging.debug(" ---> ~FM~SNFlipping unread recalc for ~SB%s~SN subscriptions to ~SB%s's blurblog~SN" % (
socialsubs.count(),
user.username
))
for socialsub in socialsubs:
socialsub.needs_unread_recalc = True
socialsub.save()
shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
shared_story.publish_update_to_subscribers()

View file

@ -17,6 +17,7 @@ from apps.rss_feeds.models import MStory, Feed, MStarredStory
from apps.social.models import MSharedStory, MSocialServices, MSocialProfile, MSocialSubscription, MCommentReply
from apps.social.models import MInteraction, MActivity, MFollowRequest
from apps.social.tasks import PostToService, EmailCommentReplies, EmailStoryReshares
from apps.social.tasks import UpdateRecalcForSubscription
from apps.analyzer.models import MClassifierTitle, MClassifierAuthor, MClassifierFeed, MClassifierTag
from apps.analyzer.models import apply_classifier_titles, apply_classifier_feeds, apply_classifier_authors, apply_classifier_tags
from apps.analyzer.models import get_classifiers_for_user, sort_classifiers_by_feed
@ -519,10 +520,8 @@ def mark_story_as_shared(request):
shared_story = MSharedStory.objects.create(**story_db)
if source_user_id:
shared_story.set_source_user_id(int(source_user_id))
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=request.user.pk)
for socialsub in socialsubs:
socialsub.needs_unread_recalc = True
socialsub.save()
UpdateRecalcForSubscription.delay(subscription_user_id=request.user.pk,
shared_story_id=str(shared_story.id))
logging.user(request, "~FCSharing ~FM%s: ~SB~FB%s" % (story.story_title[:20], comments[:30]))
else:
shared_story.comments = comments
@ -533,7 +532,6 @@ def mark_story_as_shared(request):
if original_story_found:
story.count_comments()
shared_story.publish_update_to_subscribers()
story = Feed.format_story(story)
check_all = not original_story_found