diff backend/sqlalchemy/SqlAlchemyBackend.py @ 128:32a173cb081c backend

move updating the feeds to the backend
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 22 Aug 2011 15:04:53 +0200
parents 089ee60b28fb
children 71c5dc02ff87
line wrap: on
line diff
--- a/backend/sqlalchemy/SqlAlchemyBackend.py	Mon Aug 22 14:26:54 2011 +0200
+++ b/backend/sqlalchemy/SqlAlchemyBackend.py	Mon Aug 22 15:04:53 2011 +0200
@@ -1,8 +1,11 @@
 
 from Preferences import Preferences
+from datetime import datetime, timedelta
+from sqlalchemy.sql import and_
 import Database
 import FeedList
 import FeedUpdater
+import Mapping
 import logging
 import util
 
@@ -61,6 +64,28 @@
             entry.markRead()
         self.session.commit()
 
+    def updateAllFeeds(self):
+        FeedUpdater.updateAllFeeds(self.session)
+        self.session.commit()
+
+    def expireFeedEntries(self):
+        logger = logging.getLogger("feedupdater")
+        expireDate = self._calculateExpireDate()
+        logger.info("expiring entries older than " + str(expireDate))
+        feedEntry = Mapping.feedEntryTable
+        deleteStatement = feedEntry.delete().where(
+            and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1)
+        )
+        deleteStatement.execute()
+        self.session.commit()
+
+    def _calculateExpireDate(self):
+        now = datetime.now()
+        daysToKeepFeedEntries = self.prefs.daysToKeepFeedEntries()
+        delta = timedelta(days=daysToKeepFeedEntries)
+        return now - delta
+
     def dispose(self):
         # save all uncommitted state, just in case
         self.session.commit()
+        self.session.close()