1 from couchdbkit
.exceptions
import ResourceNotFound
3 from mygpo
.core
.models
import Episode
4 from mygpo
.users
.models
import EpisodeUserState
5 from mygpo
.decorators
import repeat_on_conflict
6 from mygpo
.maintenance
.management
.changescmd
import ChangesCommand
8 class Command(ChangesCommand
):
11 super(Command
, self
).__init
__('episode-toplist-status',
12 'Episode-Toplist-Update')
15 def handle_obj(self
, seq
, doc
, actions
):
16 state
= EpisodeUserState
.wrap(doc
)
19 episode
= Episode
.get(state
.episode
)
21 except ResourceNotFound
:
25 listeners
= episode
.listener_count()
26 updated
= self
.update(episode
=episode
, listeners
=listeners
)
27 actions
['updated'] += updated
30 actions
['missing'] += 1
33 @repeat_on_conflict(['episode'])
34 def update(self
, episode
, listeners
):
35 if episode
.listeners
== listeners
:
38 episode
.listeners
= listeners
43 def get_query_params(self
):
44 return dict(include_docs
=True, filter='episode_states/has_play_events')
48 return EpisodeUserState
.get_db()