Skip to content

Commit

Permalink
Improved performance on the aggregator index page.
Browse files Browse the repository at this point in the history
The previous version generated O(N) gratuitous COUNTs.
  • Loading branch information
jacobian committed Feb 19, 2013
1 parent 8f0ff61 commit 36800b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion aggregator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions templates/aggregator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
font-weight: 600;
list-style: none;
padding: 20px 0;
}
</style>
{% endblock %}

Expand All @@ -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 %}
Expand Down

0 comments on commit 36800b9

Please sign in to comment.