From 2ccd3f5d4fb5a4916a6326f3ec7dcc53228478b4 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Sat, 30 Oct 2010 01:06:48 +0200 Subject: [PATCH] Sort entry list before cutting it off (bug 1186) The max_episodes_per_feed setting should prevent too many episodes in a single podcast (which slows down processing and loading of the episode list). In cases where the feed lists all episodes in chronological order (oldest first), the feed will at some point (episodes in the feed >= max_episodes_per_feed) stop showing new episodes. This patch fixes this by (trying to) sort the entries by update time, descending and only then cutting of the entry list. --- src/gpodder/model.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gpodder/model.py b/src/gpodder/model.py index 3c95cb50..33c8fc8a 100644 --- a/src/gpodder/model.py +++ b/src/gpodder/model.py @@ -220,7 +220,17 @@ class PodcastChannel(PodcastModelObject): # We can limit the maximum number of entries that gPodder will parse if max_episodes > 0 and len(feed.entries) > max_episodes: - entries = feed.entries[:max_episodes] + # We have to sort the entries in descending chronological order, + # because if the feed lists items in ascending order and has > + # max_episodes old episodes, new episodes will not be shown. + # See also: gPodder Bug 1186 + try: + entries = sorted(feed.entries, \ + key=lambda x: x.get('updated_parsed', (0,)*9), \ + reverse=True)[:max_episodes] + except Exception, e: + log('Could not sort episodes: %s', e, sender=self, traceback=True) + entries = feed.entries[:max_episodes] else: entries = feed.entries -- 2.11.4.GIT