changeset 160:86f828096aaf

Do not fetch and parse the feed twice when creating a new one. Pass the parsed info into the update method instead to reuse.
author dirk
date Mon, 29 Aug 2011 03:07:50 +0200
parents 7d724cf2dcf7
children 2940e74c9663
files backend/AbstractFeedUpdater.py backend/sqlalchemy/FeedUpdater.py
diffstat 2 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/backend/AbstractFeedUpdater.py	Mon Aug 29 02:41:24 2011 +0200
+++ b/backend/AbstractFeedUpdater.py	Mon Aug 29 03:07:50 2011 +0200
@@ -15,13 +15,13 @@
     def __init__(self, feed):
         self.feed = feed
 
-    def update(self):
+    def update(self, feedDict=None):
         log.info("updating " + self.feed.rss_url)
-        result = self._retrieveFeed()
-        for entry in result.entries:
-            self._normalize(entry)
-            self._processEntry(entry)
-        self._incrementFeedUpdateDate()
+        if feedDict is None:
+            result = self._retrieveFeed()
+        else:
+            result = feedDict
+        self._processEntries(result)
 
     def _retrieveFeed(self):
         result = feedparser.parse(self.feed.rss_url)
@@ -33,6 +33,12 @@
             raise FeedUpdateException("HTTP status " + str(status))
         return result
 
+    def _processEntries(self, feedDict):
+        for entry in feedDict.entries:
+            self._normalize(entry)
+            self._processEntry(entry)
+        self._incrementFeedUpdateDate()
+
     def _normalize(self, entry):
         if not hasattr(entry, "id"):
             entry.id = entry.link
--- a/backend/sqlalchemy/FeedUpdater.py	Mon Aug 29 02:41:24 2011 +0200
+++ b/backend/sqlalchemy/FeedUpdater.py	Mon Aug 29 03:07:50 2011 +0200
@@ -30,7 +30,7 @@
     newFeed = Feed(title, url)
     session.add(newFeed)
 
-    FeedUpdater(session, newFeed).update()
+    FeedUpdater(session, newFeed).update(result)
 
 
 class FeedUpdater(AbstractFeedUpdater):