changeset 189:e5d492595bdb

the view returns feed entries for a feed sorted by update date now, no need to do sorting in-memory
author dirk
date Wed, 14 Sep 2011 00:17:55 +0200
parents e26210be221f
children b7d41325386b
files backend/couchdb/CouchDbBackend.py backend/couchdb/FeedEntry.py
diffstat 2 files changed, 5 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/backend/couchdb/CouchDbBackend.py	Wed Sep 14 00:17:01 2011 +0200
+++ b/backend/couchdb/CouchDbBackend.py	Wed Sep 14 00:17:55 2011 +0200
@@ -53,8 +53,6 @@
 
     def _retrieveEntriesForSelectedFeed(self, hideReadEntries):
         viewResults = FeedEntry.entriesForFeed(self.selectedFeed, self.database)
-        # TODO update date is a string ... convert to a ListDateTimeField for better sort support
-        viewResults.sort(FeedEntry.compareByUpdateDate, reverse=True)
         if hideReadEntries:
             filterFunc = lambda feedEntry: feedEntry.read == False
             viewResults = filter(filterFunc, viewResults)
--- a/backend/couchdb/FeedEntry.py	Wed Sep 14 00:17:01 2011 +0200
+++ b/backend/couchdb/FeedEntry.py	Wed Sep 14 00:17:55 2011 +0200
@@ -1,6 +1,6 @@
 
 from backend.couchdb.ListDateTimeField import ListDateTimeField
-from couchdb.mapping import BooleanField, DateTimeField, Document, TextField
+from couchdb.mapping import BooleanField, Document, TextField
 from datetime import datetime
 import CouchDb
 
@@ -11,7 +11,7 @@
     link = TextField()
     title = TextField()
     summary = TextField()
-    updated = DateTimeField()
+    updated = ListDateTimeField()
     feed = TextField()
 
     @staticmethod
@@ -29,12 +29,10 @@
         return FeedEntry.view(database, CouchDb.readFeedEntriesByCreateDate(), endkey=end)
 
     @staticmethod
-    def compareByUpdateDate(first, second):
-        return cmp(first, second)
-
-    @staticmethod
     def entriesForFeed(feed, database):
-        viewResults = FeedEntry.view(database, CouchDb.feedEntriesByFeed(), key=feed.id)
+        ''' the definition of the view makes sure that the entries come out sorted by udpate date '''
+        viewResults = FeedEntry.view(database, CouchDb.feedEntriesByFeed(), startkey=[feed.id],
+            endkey=[feed.id, {}])
         return list(viewResults)
 
     def markRead(self, database):
@@ -47,4 +45,3 @@
         else:
             self.read = True
         self.store(database)
-