From bdb9af617a91500c7a045999ff1f74f5f8cdbeae Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Fri, 30 Nov 2012 18:13:27 +0100 Subject: Code factorization... --- source/mongodb.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source/mongodb.py') diff --git a/source/mongodb.py b/source/mongodb.py index 84e81a04..66b2865c 100644 --- a/source/mongodb.py +++ b/source/mongodb.py @@ -110,8 +110,12 @@ class Articles(object): collections = self.db.collection_names() for collection_name in collections: collection = self.db[collection_name] - articles.extend(collection.find({'type':1})) + if condition is None: + articles.extend(collection.find({"type":1}, limit=limit)) + else: + articles.extend(collection.find({"type":1, condition[0]:condition[1]}, limit=limit)) return articles + elif feed_id != None and article_id == None: # Return all the articles of a collection. collection = self.db[str(feed_id)] @@ -120,6 +124,7 @@ class Articles(object): else: cursor = collection.find({"type":1, condition[0]:condition[1]}, limit=limit) return cursor.sort([("article_date", pymongo.DESCENDING)]) + elif feed_id != None and article_id != None: # Return a precise article. collection = self.db[str(feed_id)] @@ -182,14 +187,9 @@ class Articles(object): or of all the database. """ if feed_id is not None: - collection = self.db[feed_id] - cursor = collection.find({'article_readed':False}) - return cursor.count() + return self.get_articles(feed_id=feed_id, condition=("article_readed", False)).count() else: - unread_articles = 0 - for feed_id in self.db.collection_names(): - unread_articles += self.nb_unread_articles(feed_id) - return unread_articles + return len(self.get_articles(condition=("article_readed", False))) def like_article(self, like, feed_id, article_id): """ -- cgit