aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2014-09-22 23:18:43 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2014-09-22 23:18:43 +0200
commit5fbff2420421e82498d71dddc1034fd6e9eba8e7 (patch)
treefc1d683c203aca6ecc17de507dbe8e20c1193689 /pyaggr3g470r
parentSome minor uninteresting changes. (diff)
downloadnewspipe-5fbff2420421e82498d71dddc1034fd6e9eba8e7.tar.gz
newspipe-5fbff2420421e82498d71dddc1034fd6e9eba8e7.tar.bz2
newspipe-5fbff2420421e82498d71dddc1034fd6e9eba8e7.zip
Significative performance improvement for the /unread view.
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/templates/unread.html8
-rw-r--r--pyaggr3g470r/views.py11
2 files changed, 9 insertions, 10 deletions
diff --git a/pyaggr3g470r/templates/unread.html b/pyaggr3g470r/templates/unread.html
index cdfb0dfe..9808572b 100644
--- a/pyaggr3g470r/templates/unread.html
+++ b/pyaggr3g470r/templates/unread.html
@@ -18,10 +18,10 @@
<a href="/edit_feed/{{ feed.id }}"><i class="glyphicon glyphicon-edit" title="{{ _('Edit this feed') }}"></i></a>
<a href="/mark_as/read/feed/{{ feed.id }}"><i class="glyphicon glyphicon-check" title="{{ _('Mark all feed as read') }}"></i></a>
<a href="/mark_as/unread/feed/{{ feed.id }}"><i class="glyphicon glyphicon-unchecked" title="{{ _('Mark all feed as unread') }}"></i></a>
- <h3>{{ feed.articles.all()|length }} {{ _('unread articles') }}.</h3>
+ <h3>{{ feed.articles|length }} {{ _('unread articles') }}.</h3>
</div>
</div>
- {% for number in range(0, feed.articles.all()|length-(feed.articles.all()|length % 3), 3) %}
+ {% for number in range(0, feed.articles|length-(feed.articles|length % 3), 3) %}
<div class="row">
{% for n in range(number, number+3) %}
<div class="col-xs-6 col-sm-4 col-md-4">
@@ -33,9 +33,9 @@
{% endfor %}
</div>
{% endfor %}
- {% if feed.articles.all()|length % 3 != 0 %}
+ {% if feed.articles|length % 3 != 0 %}
<div class="row">
- {% for n in range(feed.articles.all()|length-(feed.articles.all()|length % 3), feed.articles.all()|length) %}
+ {% for n in range(feed.articles|length-(feed.articles|length % 3), feed.articles|length) %}
<div class="col-xs-6 col-sm-4 col-md-4">
{% if feed.articles[n].readed %}<h3>{% else %}<h1>{% endif %}
<a href="/article/{{ feed.articles[n].id }}">{{ feed.articles[n].title|safe }}</a>
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index ef3b908e..0212e496 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -28,6 +28,7 @@ __license__ = "AGPLv3"
import os
import datetime
+from collections import namedtuple
from flask import abort, render_template, request, flash, session, \
url_for, redirect, g, current_app, make_response, jsonify
from flask.ext.login import LoginManager, login_user, logout_user, \
@@ -451,13 +452,11 @@ def unread(feed_id=None):
else:
feeds_with_unread = Feed.query.filter(Feed.user_id == g.user.id, Feed.articles.any(readed=False))
result, nb_unread = [], 0
+ light_feed = namedtuple('Feed', ['id', 'title', 'articles'], verbose=False, rename=False)
for feed in feeds_with_unread:
- new_feed = feed
- new_feed.articles = Article.query.filter(Article.user_id == g.user.id, Article.feed_id == feed.id, Article.readed == False).all()
- length = len(new_feed.articles.all())
- if length != 0:
- result.append(new_feed)
- nb_unread += length
+ articles = Article.query.filter(Article.user_id == g.user.id, Article.feed_id == feed.id, Article.readed == False).all()
+ result.append(light_feed(feed.id, feed.title, articles))
+ nb_unread += len(articles)
return render_template('unread.html', feeds=result, nb_unread=nb_unread)
@app.route('/inactives', methods=['GET'])
bgstack15