From 281b42cc53f8f5aa42089e0c16a4cec654010f80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Sat, 28 Sep 2013 18:16:46 +0200 Subject: [PATCH] fix reloading podcasts on update conflict --- mygpo/data/feeddownloader.py | 9 +++++---- mygpo/data/management/commands/tag-downloader.py | 4 ++-- mygpo/db/couchdb/podcast.py | 10 +++++++--- mygpo/maintenance/management/commands/move-subscriber-data.py | 6 +++--- mygpo/maintenance/merge.py | 4 ++-- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/mygpo/data/feeddownloader.py b/mygpo/data/feeddownloader.py index 029998b8..b9ab9473 100755 --- a/mygpo/data/feeddownloader.py +++ b/mygpo/data/feeddownloader.py @@ -37,7 +37,8 @@ from mygpo.web.logo import CoverArt from mygpo.data.podcast import subscribe_at_hub from mygpo.db.couchdb.episode import episode_for_podcast_id_url, \ episodes_for_podcast_uncached -from mygpo.db.couchdb.podcast import podcast_for_url, podcast_by_id_uncached +from mygpo.db.couchdb.podcast import podcast_for_url, podcast_by_id_uncached, \ + reload_podcast from mygpo.directory.tags import update_category from mygpo.decorators import repeat_on_conflict from mygpo.db.couchdb import get_main_database @@ -121,7 +122,7 @@ class PodcastUpdater(object): raise NoEpisodesException('no episodes found') - @repeat_on_conflict(['podcast'], reload_f=podcast_by_id_uncached) + @repeat_on_conflict(['podcast'], reload_f=reload_podcast) def _update_podcast(self, podcast, parsed): """ updates a podcast according to new parser results """ @@ -212,7 +213,7 @@ class PodcastUpdater(object): update_category(podcast) - @repeat_on_conflict(['podcast']) + @repeat_on_conflict(['podcast'], reload_f=reload_podcast) def _update_episodes(self, podcast, parsed_episodes): all_episodes = set(episodes_for_podcast_uncached(podcast)) @@ -325,7 +326,7 @@ class PodcastUpdater(object): logger.warn('Exception while updating podcast: %s', str(e)) - @repeat_on_conflict(['podcast']) + @repeat_on_conflict(['podcast'], reload_f=reload_podcast) def _mark_outdated(self, podcast, msg=''): logger.info('marking podcast outdated: %s', msg) podcast.outdated = True diff --git a/mygpo/data/management/commands/tag-downloader.py b/mygpo/data/management/commands/tag-downloader.py index 636af199..dbeb0002 100644 --- a/mygpo/data/management/commands/tag-downloader.py +++ b/mygpo/data/management/commands/tag-downloader.py @@ -6,7 +6,7 @@ from mygpo.decorators import repeat_on_conflict from mygpo.core.models import Podcast from mygpo.data import delicious from mygpo.maintenance.management.podcastcmd import PodcastCommand -from mygpo.db.couchdb.podcast import podcast_by_id +from mygpo.db.couchdb.podcast import reload_podcast SOURCE = 'delicious' @@ -41,7 +41,7 @@ class Command(PodcastCommand): self.update(podcast=p, tags=tags) - @repeat_on_conflict(['podcast'], reload_f=lambda x: podcast_by_id(x.get_id())) + @repeat_on_conflict(['podcast'], reload_f=reload_podcast) def update(self, podcast, tags): podcast.tags[SOURCE] = tags podcast.save() diff --git a/mygpo/db/couchdb/podcast.py b/mygpo/db/couchdb/podcast.py index e7465a51..4720565f 100644 --- a/mygpo/db/couchdb/podcast.py +++ b/mygpo/db/couchdb/podcast.py @@ -582,7 +582,11 @@ def search(q, offset=0, num_results=20): return [], 0 -@repeat_on_conflict(['podcast']) +def reload_podcast(podcast): + return podcast_by_id_uncached(p.get_id()) + + +@repeat_on_conflict(['podcast'], reload_f=reload_podcast) def update_additional_data(podcast, twitter): podcast.twitter = twitter podcast.save() @@ -591,7 +595,7 @@ def update_additional_data(podcast, twitter): cache.clear() -@repeat_on_conflict(['podcast']) +@repeat_on_conflict(['podcast'], reload_f=reload_podcast) def update_related_podcasts(podcast, related): if podcast.related_podcasts == related: return @@ -600,6 +604,6 @@ def update_related_podcasts(podcast, related): podcast.save() -@repeat_on_conflict(['podcast']) +@repeat_on_conflict(['podcast'], reload_f=reload_podcast) def delete_podcast(podcast): podcast.delete() diff --git a/mygpo/maintenance/management/commands/move-subscriber-data.py b/mygpo/maintenance/management/commands/move-subscriber-data.py index a23f35e0..2f64afac 100755 --- a/mygpo/maintenance/management/commands/move-subscriber-data.py +++ b/mygpo/maintenance/management/commands/move-subscriber-data.py @@ -5,8 +5,8 @@ from django.core.management.base import BaseCommand from mygpo.utils import progress from mygpo.core.models import Podcast from mygpo.decorators import repeat_on_conflict -from mygpo.db.couchdb.podcast import podcast_count, podcast_by_id, \ - all_podcasts, subscriberdata_for_podcast +from mygpo.db.couchdb.podcast import podcast_count, all_podcasts, \ + subscriberdata_for_podcast, reload_podcast class Command(BaseCommand): @@ -52,7 +52,7 @@ class Command(BaseCommand): return True - @repeat_on_conflict(['podcast'], reload_f=lambda p: podcast_by_id(p.get_id())) + @repeat_on_conflict(['podcast'], reload_f=reload_podcast) def update_podcast(self, podcast): if len(podcast.subscribers) > 2: podcast.subscribers = podcast.subscribers[-2:] diff --git a/mygpo/maintenance/merge.py b/mygpo/maintenance/merge.py index 1cdfdaaf..482c437d 100644 --- a/mygpo/maintenance/merge.py +++ b/mygpo/maintenance/merge.py @@ -6,7 +6,7 @@ import restkit from mygpo import utils from mygpo.decorators import repeat_on_conflict -from mygpo.db.couchdb.podcast import delete_podcast +from mygpo.db.couchdb.podcast import delete_podcast, reload_podcast from mygpo.db.couchdb.episode import episodes_for_podcast_uncached from mygpo.db.couchdb.podcast_state import all_podcast_states, \ delete_podcast_state, update_podcast_state_podcast, merge_podcast_states @@ -72,7 +72,7 @@ class PodcastMerger(object): em = EpisodeMerger(episode, ep, self.actions) em.merge() - @repeat_on_conflict(['podcast1', 'podcast2']) + @repeat_on_conflict(['podcast1', 'podcast2'], reload_f=reload_podcast) def _merge_objs(self, podcast1, podcast2): podcast1.merged_ids = set_filter(podcast1.get_id(), -- 2.11.4.GIT