fix cmd update-related-podcasts
authorStefan Kögl <stefan@skoegl.net>
Sat, 27 Apr 2013 17:06:35 +0000 (27 19:06 +0200)
committerStefan Kögl <stefan@skoegl.net>
Sat, 27 Apr 2013 17:06:35 +0000 (27 19:06 +0200)
mygpo/data/management/commands/update-related-podcasts.py
mygpo/db/couchdb/podcast.py
mygpo/db/couchdb/podcast_state.py

index c764154..b128e5b 100644 (file)
@@ -7,7 +7,8 @@ from mygpo.decorators import repeat_on_conflict
 from mygpo.core.models import Podcast
 from mygpo.data.podcast import calc_similar_podcasts
 from mygpo.utils import progress
-from mygpo.db.couchdb.podcast import podcast_count, all_podcasts
+from mygpo.db.couchdb.podcast import podcast_count, all_podcasts, \
+    update_related_podcasts
 
 
 class Command(BaseCommand):
@@ -32,11 +33,6 @@ class Command(BaseCommand):
 
             related = map(get_podcast, l)
 
-            @repeat_on_conflict(['podcast'])
-            def _update(podcast, related):
-                podcast.related_podcasts = related
-                podcast.save()
-
-            _update(podcast=podcast, related=related)
+            update_related_podcasts(podcast, related)
 
             progress(n+1, total)
index dc96834..6336301 100644 (file)
@@ -549,3 +549,12 @@ def update_additional_data(podcast, twitter):
 
     # clear the whole cache until we have a better invalidation mechanism
     cache.clear()
+
+
+@repeat_on_conflict(['podcast'])
+def update_related_podcasts(podcast, related):
+    if podcast.related_podcasts == related:
+        return
+
+    podcast.related_podcasts = related
+    podcast.save()
index 0ffdea2..ed3ba7e 100644 (file)
@@ -35,6 +35,7 @@ def subscribed_users(podcast):
         )
 
     users = (r['key'][1] for r in res)
+    return users
 
 
 def subscribed_podcast_ids_by_user_id(user_id):
@@ -42,6 +43,8 @@ def subscribed_podcast_ids_by_user_id(user_id):
     if not user_id:
         raise QueryParameterMissing('user_id')
 
+    db = get_main_database()
+
     subscribed = db.view('subscriptions/by_user',
             startkey    = [user_id, True, None, None],
             endkey      = [user_id, True, {}, {}],