mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Using queue for scheduling feed fetches on load.
This commit is contained in:
parent
9e067ebb37
commit
5ed2109bcf
3 changed files with 37 additions and 8 deletions
|
@ -38,6 +38,7 @@ from apps.social.models import MSharedStory, MSocialProfile, MSocialServices
|
|||
from apps.social.models import MSocialSubscription, MActivity
|
||||
from apps.categories.models import MCategory
|
||||
from apps.social.views import load_social_page
|
||||
from apps.rss_feeds.tasks import ScheduleImmediateFetches
|
||||
from utils import json_functions as json
|
||||
from utils.user_functions import get_user, ajax_login_required
|
||||
from utils.feed_functions import relative_timesince
|
||||
|
@ -219,18 +220,22 @@ def load_feeds(request):
|
|||
|
||||
user_subs = UserSubscription.objects.select_related('feed').filter(user=user)
|
||||
|
||||
scheduled_feeds = []
|
||||
for sub in user_subs:
|
||||
pk = sub.feed_id
|
||||
if update_counts:
|
||||
sub.calculate_feed_scores(silent=True)
|
||||
feeds[pk] = sub.canonical(include_favicon=include_favicons)
|
||||
if not sub.feed.active and not sub.feed.has_feed_exception and not sub.feed.has_page_exception:
|
||||
sub.feed.count_subscribers()
|
||||
sub.feed.schedule_feed_fetch_immediately()
|
||||
if sub.active and sub.feed.active_subscribers <= 0:
|
||||
sub.feed.count_subscribers()
|
||||
sub.feed.schedule_feed_fetch_immediately()
|
||||
|
||||
scheduled_feeds.append(sub.feed.pk)
|
||||
elif sub.active and sub.feed.active_subscribers <= 0:
|
||||
scheduled_feeds.append(sub.feed.pk)
|
||||
|
||||
if len(scheduled_feeds) > 0:
|
||||
logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." %
|
||||
len(scheduled_feeds))
|
||||
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds))
|
||||
|
||||
starred_count = MStarredStory.objects(user_id=user.pk).count()
|
||||
|
||||
social_params = {
|
||||
|
|
|
@ -226,7 +226,17 @@ class Feed(models.Model):
|
|||
@classmethod
|
||||
def merge_feeds(cls, *args, **kwargs):
|
||||
return merge_feeds(*args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def schedule_feed_fetches_immediately(cls, feed_ids):
|
||||
logging.info(" ---> ~SN~FMScheduling immediate fetch of ~SB%s~SN feeds..." %
|
||||
len(feed_ids))
|
||||
|
||||
feeds = Feed.objects.filter(pk__in=feed_ids)
|
||||
for feed in feeds:
|
||||
feed.count_subscribers()
|
||||
feed.schedule_feed_fetch_immediately(verbose=False)
|
||||
|
||||
@property
|
||||
def favicon_fetching(self):
|
||||
return bool(not (self.favicon_not_found or self.favicon_color))
|
||||
|
@ -1222,8 +1232,10 @@ class Feed(models.Model):
|
|||
|
||||
self.save()
|
||||
|
||||
def schedule_feed_fetch_immediately(self):
|
||||
logging.debug(' ---> [%-30s] Scheduling feed fetch immediately...' % (unicode(self)[:30]))
|
||||
def schedule_feed_fetch_immediately(self, verbose=True):
|
||||
if verbose:
|
||||
logging.debug(' ---> [%-30s] Scheduling feed fetch immediately...' % (unicode(self)[:30]))
|
||||
|
||||
self.next_scheduled_update = datetime.datetime.utcnow()
|
||||
|
||||
return self.save()
|
||||
|
|
|
@ -149,3 +149,15 @@ class BackupMongo(Task):
|
|||
shutil.rmtree(dir_name)
|
||||
os.remove(filename)
|
||||
logging.debug(' ---> ~FRFinished uploading ~SB~FM%s~SN~FR to S3.' % filename)
|
||||
|
||||
|
||||
class ScheduleImmediateFetches(Task):
|
||||
|
||||
def run(self, feed_ids, **kwargs):
|
||||
from apps.rss_feeds.models import Feed
|
||||
|
||||
if not isinstance(feed_ids, list):
|
||||
feed_ids = [feed_ids]
|
||||
|
||||
Feed.schedule_feed_fetches_immediately(feed_ids)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue