aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2012-11-30 14:29:12 +0100
committerCédric Bonhomme <kimble.mandel@gmail.com>2012-11-30 14:29:12 +0100
commit1f45444aa2da418c3c9dfe70e7ef39c0170b6f36 (patch)
tree88368039a5b63a98e9ae7ec37f20d50d3ba77234 /source
parentRemoved useless function in mongodb.py. (diff)
downloadnewspipe-1f45444aa2da418c3c9dfe70e7ef39c0170b6f36.tar.gz
newspipe-1f45444aa2da418c3c9dfe70e7ef39c0170b6f36.tar.bz2
newspipe-1f45444aa2da418c3c9dfe70e7ef39c0170b6f36.zip
Performance MongoDB imptovements (get_gavorites() function).
Diffstat (limited to 'source')
-rw-r--r--source/mongodb.py18
-rwxr-xr-xsource/pyAggr3g470r.py2
-rw-r--r--source/templates/favorites.html5
3 files changed, 10 insertions, 15 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):
"""
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index 3f5132df..7455bc1c 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -750,7 +750,7 @@ class pyAggr3g470r(object):
feeds = self.mongo.get_all_feeds()
articles = {}
for feed in feeds:
- articles[feed["feed_id"]] = self.mongo.get_articles_from_collection(feed["feed_id"])
+ articles[feed["feed_id"]] = self.mongo.get_favorites(feed["feed_id"])
tmpl = lookup.get_template("favorites.html")
return tmpl.render(feeds=feeds, \
articles=articles)
diff --git a/source/templates/favorites.html b/source/templates/favorites.html
index beb76ff8..5eba8a3c 100644
--- a/source/templates/favorites.html
+++ b/source/templates/favorites.html
@@ -10,7 +10,6 @@ import utils
new_feed_section = True
%>
%for article in articles[feed["feed_id"]]:
- %if article["article_like"]:
<%
if new_feed_section:
new_feed_section = False
@@ -26,8 +25,6 @@ import utils
%>
${title}
-
- ${article["article_date"].strftime('%Y-%m-%d %H:%M')} - <a class="tooltip" href="/article/${feed['feed_id']}:${article['article_id']}" rel="noreferrer" target="_blank">${article["article_title"][:150]}<span class="classic">${description}</span></a><br />
- %endif
+ ${article["article_date"].strftime('%Y-%m-%d %H:%M')} - <a class="tooltip" href="/article/${feed['feed_id']}:${article['article_id']}" rel="noreferrer" target="_blank">${article["article_title"][:150]}<span class="classic">${description}</span></a><br />
%endfor
%endfor \ No newline at end of file
bgstack15