aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2020-04-03 10:06:59 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2020-04-03 10:06:59 +0200
commit3fdf0aae1dd1bfd76cdacb3eb1946b58b35d3532 (patch)
treec00e5f168d079f6eda4817b1ec9e4ae71333a414
parentUpdated werkzeug. (diff)
downloadnewspipe-3fdf0aae1dd1bfd76cdacb3eb1946b58b35d3532.tar.gz
newspipe-3fdf0aae1dd1bfd76cdacb3eb1946b58b35d3532.tar.bz2
newspipe-3fdf0aae1dd1bfd76cdacb3eb1946b58b35d3532.zip
speed improvements to the /history page
-rw-r--r--newspipe/controllers/article.py9
-rw-r--r--newspipe/templates/history.html6
2 files changed, 8 insertions, 7 deletions
diff --git a/newspipe/controllers/article.py b/newspipe/controllers/article.py
index 8468248e..bbb83b62 100644
--- a/newspipe/controllers/article.py
+++ b/newspipe/controllers/article.py
@@ -74,17 +74,18 @@ class ArticleController(AbstractController):
Sort articles by year and month.
"""
articles_counter = Counter()
- articles = self.read()
+ articles = self.read_light()
if year is not None:
articles = articles.filter(sqlalchemy.extract("year", Article.date) == year)
if month is not None:
articles = articles.filter(
sqlalchemy.extract("month", Article.date) == month
)
- for article in articles.all():
- if year is not None:
+ if year is not None:
+ for article in articles.all():
articles_counter[article.date.month] += 1
- else:
+ else:
+ for article in articles.all():
articles_counter[article.date.year] += 1
return articles_counter, articles
diff --git a/newspipe/templates/history.html b/newspipe/templates/history.html
index ba567106..0638993c 100644
--- a/newspipe/templates/history.html
+++ b/newspipe/templates/history.html
@@ -10,11 +10,11 @@
<h3>{{ year }}</h3>
{% endif %}
<ul class="list-group">
- {% for article in articles_counter | sort(reverse = True) %}
+ {% for date in articles_counter | sort(reverse = True) %}
{% if year == None %}
- <li class="list-group-item"><a href="{{ url_for("articles.history", year=article) }}">{{ article }}</a> : {{ articles_counter[article] }} articles</li>
+ <li class="list-group-item"><a href="{{ url_for("articles.history", year=date) }}">{{ date }}</a> : {{ articles_counter[date] }} articles</li>
{% elif month == None %}
- <li class="list-group-item"><a href="{{ url_for("articles.history", year=year, month=article) }}">{{ article | month_name }}</a> : {{ articles_counter[article] }} articles</li>
+ <li class="list-group-item"><a href="{{ url_for("articles.history", year=year, month=date) }}">{{ date | month_name }}</a> : {{ articles_counter[date] }} articles</li>
{% else %}
{% for article in articles %}
<li class="list-group-item">{{ article.date | datetime }} - <a href="/article/{{ article.id }}">{{ article.title | safe }}</a></li>
bgstack15