diff options
author | Cédric Bonhomme <kimble.mandel@gmail.com> | 2012-11-30 14:29:12 +0100 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel@gmail.com> | 2012-11-30 14:29:12 +0100 |
commit | 1f45444aa2da418c3c9dfe70e7ef39c0170b6f36 (patch) | |
tree | 88368039a5b63a98e9ae7ec37f20d50d3ba77234 /source/mongodb.py | |
parent | Removed useless function in mongodb.py. (diff) | |
download | newspipe-1f45444aa2da418c3c9dfe70e7ef39c0170b6f36.tar.gz newspipe-1f45444aa2da418c3c9dfe70e7ef39c0170b6f36.tar.bz2 newspipe-1f45444aa2da418c3c9dfe70e7ef39c0170b6f36.zip |
Performance MongoDB imptovements (get_gavorites() function).
Diffstat (limited to 'source/mongodb.py')
-rw-r--r-- | source/mongodb.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/source/mongodb.py b/source/mongodb.py index e11cc498..6b15f0fd 100644 --- a/source/mongodb.py +++ b/source/mongodb.py @@ -151,23 +151,21 @@ class Articles(object): collection = self.db[feed_id] cursor = collection.find({'type':1, 'article_like':True}) return cursor - + else: + favorites = [] + for feed_id in self.db.collection_names(): + favorites += self.get_favorites(feed_id) + return favorites + def nb_favorites(self, feed_id=None): """ Return the number of favorites articles of a feed or of all the database. """ if feed_id is not None: - # only for a feed - collection = self.db[feed_id] - cursor = collection.find({'type':1, 'article_like':True}) - return cursor.count() + return self.get_favorites(feed_id).count() else: - # for all feeds - nb_favorites = 0 - for feed_id in self.db.collection_names(): - nb_favorites += self.nb_favorites(feed_id) - return nb_favorites + return len(self.get_favorites()) def nb_mail_notifications(self): """ |