Merge lp:~ronnie.vd.c/loco-team-portal/reduced_venue_page_queries into lp:loco-team-portal

Proposed by Ronnie
Status: Merged
Approved by: Chris Johnston
Approved revision: 510
Merged at revision: 514
Proposed branch: lp:~ronnie.vd.c/loco-team-portal/reduced_venue_page_queries
Merge into: lp:loco-team-portal
Diff against target: 127 lines (+47/-47)
2 files modified
loco_directory/templates/venues/venue_list.html (+35/-41)
loco_directory/venues/views.py (+12/-6)
To merge this branch: bzr merge lp:~ronnie.vd.c/loco-team-portal/reduced_venue_page_queries
Reviewer Review Type Date Requested Status
Chris Johnston Approve
Review via email: mp+82058@code.launchpad.net

Commit message

Reduced the amount of queries from 800+ to 10 on the event venue list page

Description of the change

Reduced the amount of queries from 800+ to 10 on the event venue list page

Viewing the amount of queries can be done with this example:
http://stackoverflow.com/questions/1074212/show-the-sql-django-is-running/3930290#3930290

To post a comment you must log in.
Revision history for this message
Chris Johnston (cjohnston) wrote :

Works for me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/templates/venues/venue_list.html'
2--- loco_directory/templates/venues/venue_list.html 2011-10-05 00:50:53 +0000
3+++ loco_directory/templates/venues/venue_list.html 2011-11-12 23:22:24 +0000
4@@ -12,45 +12,42 @@
5
6 <h2>{% trans "Ubuntu LoCo Event Venues" %}</h2>
7
8- {% if venue_list %}
9+ {% if continent_list or venues_with_country or venues_without_country %}
10 <p>{% trans "Select a Venue below to see more information about it:" %}</p>
11-
12- {% for continent in continents %}
13- {% if continent.related_venues %}
14- <div class="venue-list">
15- <h3>{{continent.name}}</h3>
16- <ul>
17- {% for country in continent.related_countries %}
18- {% if country.related_venues %}
19- <li><h3>{{country.name}}</h3>
20- {% for venue in country.related_venues %}
21- <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
22- {% endfor %}
23- </li>
24- {% endif %}
25- {% endfor %}
26- </ul>
27- </div>
28- {% endif %}
29- {% endfor %}
30-
31- {% if countries_without_continent_have_venues %}
32- <div class="venue-list">
33- <h3>{% trans "Countries without Continent" %}</h3>
34- <ul>
35- {% for country in countries_without_continent %}
36- {% if country.related_venues %}
37- <li><h3>{{country.name}}</h3>
38- {% for venue in country.related_venues %}
39- <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
40- {% endfor %}
41- </li>
42- {% endif %}
43- {% endfor %}
44- </ul>
45- </div>
46- {% endif %}
47-
48+ {% if continent_list %}
49+ {% for continent in continent_list %}
50+ <div class="venue-list">
51+ <h3>{{ continent.name }}</h3>
52+ <ul>
53+ {% regroup continent.venue_list by country as country_list %}
54+ {% for country in country_list %}
55+ <li><h3>{{ country.grouper }}</h3>
56+ {% for venue in country.list %}
57+ <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
58+ {% endfor %}
59+ </li>
60+ {% endfor %}
61+ </ul>
62+ </div>
63+ {% endfor %}
64+ {% endif %}
65+
66+ {% if venues_with_country %}
67+ <div class="venue-list">
68+ <h3>{% trans "Countries without Continent" %}</h3>
69+ <ul>
70+ {% regroup venues_with_country by country as country_list %}
71+ {% for country in country_list %}
72+ <li><h3>{{ country.grouper }}</h3>
73+ {% for venue in country.list %}
74+ <p><a title="{% trans "show venue details" %}" href="{{ venue.get_absolute_url }}">{{ venue.name }}{% if venue.city %}, {{ venue.city }}{% endif %}{% if venue.spr %}, {{ venue.spr }}{% endif %}</a></p>
75+ {% endfor %}
76+ </li>
77+ {% endfor %}
78+ </ul>
79+ </div>
80+ {% endif %}
81+
82 {% if venues_without_country %}
83 <div class="venue-list">
84 <h3>{% trans "Venues without Country" %}</h3>
85@@ -63,11 +60,8 @@
86 </ul>
87 </div>
88 {% endif %}
89-
90-
91 {% else %}
92 <p>{% trans "There are currently no LoCo Venues :(" %}</p>
93 {% endif %}
94-
95 </article>
96 {% endblock %}
97
98=== modified file 'loco_directory/venues/views.py'
99--- loco_directory/venues/views.py 2011-03-18 13:37:13 +0000
100+++ loco_directory/venues/views.py 2011-11-12 23:22:24 +0000
101@@ -18,14 +18,20 @@
102 """
103 a list with all venues
104 """
105- venue_list = Venue.objects.all().order_by('country')
106+ venue_base_query = Venue.objects.select_related('country').order_by('country')
107+
108+ continent_list = []
109+ for continent in Continent.objects.filter(country__venue__isnull=False).distinct():
110+ continent.venue_list = venue_base_query.filter(country__continents=continent)
111+ continent_list.append(continent)
112+
113+ venues_with_country = venue_base_query.filter(country__isnull=False, country__continents__isnull=True)
114+ venues__without_country = venue_base_query.filter(country__isnull=True)
115
116 context = {
117- 'venue_list': venue_list,
118- 'continents': Continent.objects.all().order_by('name'),
119- 'countries_without_continent': countries_without_continent().order_by('name'),
120- 'countries_without_continent_have_venues': countries_without_continent_have_venues(),
121- 'venues_without_country': venues_without_country().order_by('name'),
122+ 'continent_list': continent_list,
123+ 'venues_with_country': venues_with_country,
124+ 'venues_without_country': venues__without_country,
125 'colcycle' : simple_iterator('col_left', 'col_right'),
126
127 }

Subscribers

People subscribed via source and target branches