mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Only fetching feeds immediately if necessary.
This commit is contained in:
parent
c50808a382
commit
9599cf65f2
3 changed files with 18 additions and 9 deletions
|
@ -258,7 +258,7 @@ def load_feeds(request):
|
|||
if len(scheduled_feeds) > 0 and request.user.is_authenticated():
|
||||
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))
|
||||
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk))
|
||||
|
||||
starred_counts, starred_count = MStarredStoryCounts.user_counts(user.pk, include_total=True)
|
||||
if not starred_count and len(starred_counts):
|
||||
|
@ -343,7 +343,7 @@ def load_feeds_flat(request):
|
|||
if len(scheduled_feeds) > 0 and request.user.is_authenticated():
|
||||
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))
|
||||
ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk))
|
||||
|
||||
flat_folders = []
|
||||
if folders:
|
||||
|
|
|
@ -310,18 +310,27 @@ class Feed(models.Model):
|
|||
self.feed_address = "http://www.google.com/alerts/feeds/%s/%s" % (user_id, alert_id)
|
||||
|
||||
@classmethod
|
||||
def schedule_feed_fetches_immediately(cls, feed_ids):
|
||||
def schedule_feed_fetches_immediately(cls, feed_ids, user_id=None):
|
||||
if settings.DEBUG:
|
||||
logging.info(" ---> ~SN~FMSkipping the scheduling immediate fetch of ~SB%s~SN feeds (in DEBUG)..." %
|
||||
len(feed_ids))
|
||||
return
|
||||
logging.info(" ---> ~SN~FMScheduling immediate fetch of ~SB%s~SN feeds..." %
|
||||
len(feed_ids))
|
||||
|
||||
if user_id:
|
||||
user = User.objects.get(pk=user_id)
|
||||
logging.user(user, "~SN~FMScheduling immediate fetch of ~SB%s~SN feeds..." %
|
||||
len(feed_ids))
|
||||
else:
|
||||
logging.debug(" ---> ~SN~FMScheduling immediate fetch of ~SB%s~SN feeds..." %
|
||||
len(feed_ids))
|
||||
|
||||
day_ago = datetime.datetime.now() - datetime.timedelta(days=1)
|
||||
feeds = Feed.objects.filter(pk__in=feed_ids)
|
||||
for feed in feeds:
|
||||
feed.count_subscribers()
|
||||
feed.schedule_feed_fetch_immediately(verbose=False)
|
||||
if feed.active_subscribers <= 0:
|
||||
feed.count_subscribers()
|
||||
if not feed.active or feed.next_scheduled_update < day_ago:
|
||||
feed.schedule_feed_fetch_immediately(verbose=False)
|
||||
|
||||
@property
|
||||
def favicon_fetching(self):
|
||||
|
|
|
@ -197,13 +197,13 @@ class BackupMongo(Task):
|
|||
|
||||
class ScheduleImmediateFetches(Task):
|
||||
|
||||
def run(self, feed_ids, **kwargs):
|
||||
def run(self, feed_ids, user_id, **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)
|
||||
Feed.schedule_feed_fetches_immediately(feed_ids, user_id)
|
||||
|
||||
|
||||
class SchedulePremiumSetup(Task):
|
||||
|
|
Loading…
Add table
Reference in a new issue