Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved performance on the aggregator index page.

The previous version generated O(N) gratuitous COUNTs.
  • Loading branch information...
commit 36800b9c8dd90838937555c17a8391d84cf0d6b3 1 parent 8f0ff61
@jacobian jacobian authored
Showing with 9 additions and 5 deletions.
  1. +4 −1 aggregator/views.py
  2. +5 −4 templates/aggregator/index.html
View
5 aggregator/views.py
@@ -20,7 +20,10 @@ def index(request):
"""
Displays the latest feeds of each type.
"""
- ctx = {'feedtype_list': FeedType.objects.all()}
+ feeds = []
+ for ft in FeedType.objects.all():
+ feeds.append((ft, ft.items()[0:5]))
+ ctx = {'feedtype_list': feeds}
return render(request, 'aggregator/index.html', ctx)
class FeedListView(ListView):
View
9 templates/aggregator/index.html
@@ -7,6 +7,7 @@
font-weight: 600;
list-style: none;
padding: 20px 0;
+}
</style>
{% endblock %}
@@ -22,21 +23,21 @@ <h2 class="deck">This page, updated regularly, aggregates what's going on in the
</ul>
{% endif %}
-{% for feedtype in feedtype_list %}
+{% for feedtype, latest_feeds in feedtype_list %}
<div id="{{ feedtype.slug }}" class="module {% cycle "first" "last" %}">
<h3 class="header">
{{ feedtype.name }}
<a class="rss" href="{% url 'aggregator-feed' slug=feedtype.slug %}">RSS</a>
</h3>
- {% for item in feedtype.items|slice:":5" %}
+ {% for item in latest_feeds %}
<h5><a href="{{ item.link }}">{{ item.title }}</a></h5>
<p class="date">{{ item.date_modified|date:"N jS, Y \a\t P" }} by <a href="{{ item.feed.public_url }}">{{ item.feed.title }}</a></p>
{% endfor %}
<p>
- {% if feedtype.items|length %}
+ {% if latest_feeds %}
<a href="{% url 'community-feed-list' feedtype.slug %}">View more</a>
{% endif %}
- {% if feedtype.items and feedtype.can_self_add %}
+ {% if latest_feeds and feedtype.can_self_add %}
or
{% endif %}
{% if feedtype.can_self_add %}
Please sign in to comment.
Something went wrong with that request. Please try again.