comparison 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
comparison
equal deleted inserted replaced
127:c923e4c57a81 128:32a173cb081c
1 1
2 from Preferences import Preferences 2 from Preferences import Preferences
3 from datetime import datetime, timedelta
4 from sqlalchemy.sql import and_
3 import Database 5 import Database
4 import FeedList 6 import FeedList
5 import FeedUpdater 7 import FeedUpdater
8 import Mapping
6 import logging 9 import logging
7 import util 10 import util
8 11
9 class SqlAlchemyBackend(object): 12 class SqlAlchemyBackend(object):
10 ''' 13 '''
59 def markFeedEntriesAsRead(self, entries): 62 def markFeedEntriesAsRead(self, entries):
60 for entry in entries: 63 for entry in entries:
61 entry.markRead() 64 entry.markRead()
62 self.session.commit() 65 self.session.commit()
63 66
67 def updateAllFeeds(self):
68 FeedUpdater.updateAllFeeds(self.session)
69 self.session.commit()
70
71 def expireFeedEntries(self):
72 logger = logging.getLogger("feedupdater")
73 expireDate = self._calculateExpireDate()
74 logger.info("expiring entries older than " + str(expireDate))
75 feedEntry = Mapping.feedEntryTable
76 deleteStatement = feedEntry.delete().where(
77 and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1)
78 )
79 deleteStatement.execute()
80 self.session.commit()
81
82 def _calculateExpireDate(self):
83 now = datetime.now()
84 daysToKeepFeedEntries = self.prefs.daysToKeepFeedEntries()
85 delta = timedelta(days=daysToKeepFeedEntries)
86 return now - delta
87
64 def dispose(self): 88 def dispose(self):
65 # save all uncommitted state, just in case 89 # save all uncommitted state, just in case
66 self.session.commit() 90 self.session.commit()
91 self.session.close()