changeset 174:d0ced79b5030

implement expiring read feed entries
author dirk
date Fri, 09 Sep 2011 17:21:34 +0200
parents 3bcf39181f6e
children 57e324fa4350
files backend/couchdb/CouchApp/feedworm/views/read_feedEntries_by_create_date/map.js backend/couchdb/CouchDb.py backend/couchdb/CouchDbBackend.py backend/couchdb/FeedEntry.py
diffstat 4 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/couchdb/CouchApp/feedworm/views/read_feedEntries_by_create_date/map.js	Fri Sep 09 17:21:34 2011 +0200
@@ -0,0 +1,7 @@
+function(doc)
+{
+    if (doc.doctype == "feedEntry" && doc.read)
+    {
+        emit(doc.create_timestamp, doc)
+    }
+}
--- a/backend/couchdb/CouchDb.py	Fri Sep 09 17:19:16 2011 +0200
+++ b/backend/couchdb/CouchDb.py	Fri Sep 09 17:21:34 2011 +0200
@@ -30,4 +30,7 @@
 def preference():
     return database + "/preference"
 
+def readFeedEntriesByCreateDate():
+    return database + "/read_feedEntries_by_create_date"
 
+
--- a/backend/couchdb/CouchDbBackend.py	Fri Sep 09 17:19:16 2011 +0200
+++ b/backend/couchdb/CouchDbBackend.py	Fri Sep 09 17:21:34 2011 +0200
@@ -2,10 +2,11 @@
 from FeedUpdater import FeedUpdater
 from Preferences import Preferences
 from backend.AbstractBackend import AbstractBackend
+from backend.couchdb import CouchDb
 from backend.couchdb.Feed import Feed
 from backend.couchdb.FeedEntry import FeedEntry
 import couchdb
-from backend.couchdb import CouchDb
+import logging
 
 class CouchDbBackend(AbstractBackend):
     '''
@@ -101,6 +102,8 @@
                 FeedUpdater(self.database, self.preferences()).update(feed)
 
     def expireFeedEntries(self):
-        print("Expiring feeds is not yet implemented")
-#        raise Exception("not yet implemented")
-
+        logger = logging.getLogger("expiry")
+        expireDate = self._calculateExpireDate()
+        logger.info("expiring entries older than " + str(expireDate))
+        for entry in FeedEntry.getReadFeedEntriesOlderThan(expireDate, self.database):
+            del self.database[entry.id]
--- a/backend/couchdb/FeedEntry.py	Fri Sep 09 17:19:16 2011 +0200
+++ b/backend/couchdb/FeedEntry.py	Fri Sep 09 17:21:34 2011 +0200
@@ -22,6 +22,13 @@
         except StopIteration:
             return None
 
+    @staticmethod
+    def getReadFeedEntriesOlderThan(timestamp, database):
+        end = [timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute,
+               timestamp.second]
+#        end = str(end).replace(" ", "")
+        return FeedEntry.view(database, CouchDb.readFeedEntriesByCreateDate(), endkey=end)
+
     def markRead(self, database):
         self.read = True
         self.store(database)