aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-09-23 06:56:24 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-09-23 06:56:24 +0200
commit0853263f38d6f54b2a6978d31bba643d3f1f156e (patch)
tree2a7e1eab84e6579f65d8d3c944f05e092d2aeed3 /pyaggr3g470r/views.py
parentSignificative performance improvement for the /unread view. (diff)
downloadnewspipe-0853263f38d6f54b2a6978d31bba643d3f1f156e.tar.gz
newspipe-0853263f38d6f54b2a6978d31bba643d3f1f156e.tar.bz2
newspipe-0853263f38d6f54b2a6978d31bba643d3f1f156e.zip
Significative performance improvement for the /favorites view.
Diffstat (limited to 'pyaggr3g470r/views.py')
-rw-r--r--pyaggr3g470r/views.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 0212e496..6e8b35d2 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -431,13 +431,11 @@ def favorites():
"""
feeds_with_like = Feed.query.filter(Feed.user_id == g.user.id, Feed.articles.any(like=True))
result, nb_favorites = [], 0
+ light_feed = namedtuple('Feed', ['id', 'title', 'articles'], verbose=False, rename=False)
for feed in feeds_with_like:
- new_feed = feed
- new_feed.articles = Article.query.filter(Article.user_id == g.user.id, Article.feed_id == feed.id, Article.like == True).all()
- length = len(new_feed.articles.all())
- if length != 0:
- result.append(new_feed)
- nb_favorites += length
+ articles = Article.query.filter(Article.user_id == g.user.id, Article.feed_id == feed.id, Article.like == True).all()
+ result.append(light_feed(feed.id, feed.title, articles))
+ nb_favorites += len(articles)
return render_template('favorites.html', feeds=result, nb_favorites=nb_favorites)
@app.route('/unread/<int:feed_id>', methods=['GET'])
bgstack15