update list of CouchDB views in doc
[mygpo.git] / couchdb / _design / slugs / views / missing / map.js
blobc4a700164a53eac1e3c4e9556050f243e7878d90
1 function(doc)
3     function searchPodcast(podcast, podcast_id)
4     {
5         var subscribers;
7         if(podcast.subscribers == null || podcast.subscribers.length == 0)
8         {
9             subscribers = 0;
10         }
11         else
12         {
13             subscribers = podcast.subscribers[podcast.subscribers.length-1].subscriber_count;
14         }
16         if((podcast.slug == null) && podcast.title)
17         {
18             emit(["Podcast", subscribers, podcast_id], null);
19         }
21         return subscribers;
22     }
24     function searchEpisode(episode)
25     {
26         if(episode.slug != null)
27         {
28             return;
29         }
30         if(episode.outdated == true)
31         {
32             return;
33         }
34         if(!episode.title)
35         {
36             return;
37         }
39         emit(["Episode", episode.podcast, episode.listeners], null);
40     };
42     if(doc.doc_type == "Podcast")
43     {
44         searchPodcast(doc, doc._id);
45     }
46     else if(doc.doc_type == "PodcastGroup")
47     {
48         var subscribers = 0;
50         for(var n in doc.podcasts)
51         {
52             var podcast = doc.podcasts[n];
53             subscribers += searchPodcast(podcast, podcast.id);
54         }
56         if(doc.slug == null)
57         {
58             emit(["PodcastGroup", subscribers], null);
59         }
60     }
61     else if(doc.doc_type == "Episode")
62     {
63         searchEpisode(doc);
64     }