Skip to content

Commit

Permalink
get podcasts with update-needing episodes from CouchDB (bug 1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoegl committed Aug 26, 2011
1 parent 086f833 commit fce6409
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mygpo/data/management/commands/feed-downloader.py
Expand Up @@ -37,8 +37,8 @@ def handle(self, *args, **options):
fetch_queue.append(p)

if options.get('new'):
podcasts = models.Podcast.objects.filter(episode__title='', episode__outdated=False).distinct()
fetch_queue.extend(podcasts)
podcasts = self.get_podcast_with_new_episodes()
fetch_queue.extend(list(podcasts))

if options.get('random'):
fetch_queue = models.Podcast.objects.all().order_by('?')
Expand All @@ -64,3 +64,15 @@ def handle(self, *args, **options):
print 'Updating %d podcasts...' % len(fetch_queue)
feeddownloader.update_podcasts(fetch_queue)


def get_podcast_with_new_episodes(self):
db = newmodels.Podcast.get_db()
res = db.view('maintenance/episodes_need_update',
group_level = 1,
reduce = True,
)

for r in res:
podcast_id = r['key']
podcast = newmodels.Podcast.get(podcast_id)
yield podcast.get_old_obj()
10 changes: 10 additions & 0 deletions mygpo/maintenance/_design/views/episodes_need_update/map.js
@@ -0,0 +1,10 @@
function(doc)
{
if(doc.doc_type == "Episode")
{
if(!doc.title && !doc.outdated)
{
emit(doc.podcast, null);
}
}
}
@@ -0,0 +1 @@
_count

0 comments on commit fce6409

Please sign in to comment.