From 02cb27f9c9116355702d2359adc2b9833e8f9c10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Wed, 18 Jun 2014 20:03:21 +0200 Subject: [PATCH] [Migration] remove podcasts_groups_by_id --- mygpo/db/couchdb/podcast.py | 55 --------------------------------------------- mygpo/share/views.py | 13 ++++++++--- 2 files changed, 10 insertions(+), 58 deletions(-) diff --git a/mygpo/db/couchdb/podcast.py b/mygpo/db/couchdb/podcast.py index 9a16fddb..fb9d1aaa 100644 --- a/mygpo/db/couchdb/podcast.py +++ b/mygpo/db/couchdb/podcast.py @@ -21,51 +21,6 @@ import logging logger = logging.getLogger(__name__) -def podcasts_groups_by_id(ids): - """ gets podcast groups and top-level podcasts for the given ids """ - - if ids is None: - raise QueryParameterMissing('ids') - - if not ids: - return - - db = get_main_database() - res = db.view('podcasts/podcasts_groups', - keys = ids, - include_docs = True, - ) - - for r in res: - obj = _wrap_pg(r) - - if not obj: - yield None - continue - - if obj.needs_update: - incomplete_obj.send_robust(sender=obj) - - yield obj - - -def _wrap_pg(doc): - - doc = doc['doc'] - - if not doc: - return None - - if doc['doc_type'] == 'Podcast': - return Podcast.wrap(doc) - - elif doc['doc_type'] == 'PodcastGroup': - return PodcastGroup.wrap(doc) - - else: - logger.error('received unknown doc_type "%s"', doc['doc_type']) - - def podcasts_to_dict(ids, use_cache=False): if ids is None: @@ -124,16 +79,6 @@ def subscriberdata_for_podcast(podcast_id): return data - -def _wrap_podcast_group(res): - if res['doc']['doc_type'] == 'Podcast': - return Podcast.wrap(res['doc']) - else: - pg = PodcastGroup.wrap(res['doc']) - id = res['key'] - return pg.get_podcast_by_id(id) - - def search_wrapper(result): doc = result['doc'] if doc['doc_type'] == 'Podcast': diff --git a/mygpo/share/views.py b/mygpo/share/views.py index 8e746c70..2a8f3ef9 100644 --- a/mygpo/share/views.py +++ b/mygpo/share/views.py @@ -24,7 +24,6 @@ from mygpo.directory.views import search as directory_search from mygpo.decorators import repeat_on_conflict from mygpo.flattr import Flattr from mygpo.userfeeds.feeds import FavoriteFeed -from mygpo.db.couchdb.podcast import podcasts_groups_by_id from mygpo.db.couchdb.podcastlist import podcastlist_for_user_slug, \ podcastlists_for_user, add_podcast_to_podcastlist, \ remove_podcast_from_podcastlist, delete_podcastlist @@ -94,7 +93,7 @@ def list_show(request, plist, owner): plist = proxy_object(plist) - podcasts = list(podcasts_groups_by_id(plist.podcasts)) + podcasts = get_podcasts_groups(plist.podcasts) plist.podcasts = podcasts max_subscribers = max([p.subscriber_count() for p in podcasts] + [0]) @@ -115,7 +114,7 @@ def list_show(request, plist, owner): @list_decorator(must_own=False) def list_opml(request, plist, owner): - podcasts = podcasts_groups_by_id(plist.podcasts) + podcasts = get_podcasts_groups(plist.podcasts) return format_podcast_list(podcasts, 'opml', plist.title) @@ -324,3 +323,11 @@ def set_token_public(request, token_name, public): _update(user=request.user) return HttpResponseRedirect(reverse('share')) + + +def get_podcasts_groups(ids): + # this could be optimized by using a View + groups = PodcastGroup.objects.filter(id__in=ids) + podcasts = PodcastGroup.objects.filter(id__in_ids) + # TODO: bring in right order, according to IDs + return list(groups) + list(podcasts) -- 2.11.4.GIT