Remove episodes that have been removed from the feed (bug 458)
Episode that have not been downloaded (or have been deleted since) and that do not appear in the feed are now purged from the database after a feed update to avoid the database getting filled with orphaned episodes. Based on a patch by Neal Cox.
This commit is contained in:
parent
621070b357
commit
f954691797
|
@ -649,3 +649,14 @@ class Database(object):
|
|||
cur.execute("DELETE FROM episodes WHERE channel_id = ? AND state != ?", (channel_id, gpodder.STATE_DOWNLOADED, ))
|
||||
self.lock.release()
|
||||
|
||||
def delete_episode_by_guid(self, guid, channel_id):
|
||||
"""
|
||||
Deletes episodes that have a specific GUID for
|
||||
a given channel. Used after feed updates for
|
||||
episodes that have disappeared from the feed.
|
||||
"""
|
||||
cur = self.cursor(lock=True)
|
||||
cur.execute('DELETE FROM episodes WHERE channel_id = ? AND guid = ?', \
|
||||
(channel_id, guid))
|
||||
self.lock.release()
|
||||
|
||||
|
|
|
@ -205,6 +205,18 @@ class PodcastChannel(PodcastModelObject):
|
|||
|
||||
episode.save()
|
||||
|
||||
# Remove "unreachable" episodes - episodes that have not been
|
||||
# downloaded and that the feed does not list as downloadable anymore
|
||||
if self.id is not None:
|
||||
seen_guids = set(e.guid for e in feed.entries if hasattr(e, 'guid'))
|
||||
episodes_to_purge = (e for e in existing if \
|
||||
e.state != gpodder.STATE_DOWNLOADED and \
|
||||
e.guid not in seen_guids and e.guid is not None)
|
||||
for episode in episodes_to_purge:
|
||||
log('Episode removed from feed: %s (%s)', episode.title, \
|
||||
episode.guid, sender=self)
|
||||
self.db.delete_episode_by_guid(episode.guid, self.id)
|
||||
|
||||
# This *might* cause episodes to be skipped if there were more than
|
||||
# max_episodes_per_feed items added to the feed between updates.
|
||||
# The benefit is that it prevents old episodes from apearing as new
|
||||
|
|
Loading…
Reference in New Issue