Merge lp:~mhall119/loco-team-portal/speed-up-teams-list into lp:loco-team-portal

Proposed by Michael Hall
Status: Merged
Approved by: Chris Johnston
Approved revision: 448
Merged at revision: 450
Proposed branch: lp:~mhall119/loco-team-portal/speed-up-teams-list
Merge into: lp:loco-team-portal
Diff against target: 75 lines (+12/-11)
3 files modified
loco_directory/teams/models.py (+11/-6)
loco_directory/teams/views.py (+0/-2)
loco_directory/templates/teams/team_list.html (+1/-3)
To merge this branch: bzr merge lp:~mhall119/loco-team-portal/speed-up-teams-list
Reviewer Review Type Date Requested Status
Chris Johnston Approve
Review via email: mp+66342@code.launchpad.net

Commit message

Reduces the number of DB hits and code process for the teams list.

Description of the change

Overview
========
Reduce the number of DB hits and code process for the teams list

Details
=======
There was a lot of unnecessary calls to the DB and list processing when generating the teams list. These changes reduce the amount of work that goes into generating this page.

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

Looks great

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/teams/models.py'
2--- loco_directory/teams/models.py 2011-06-17 17:10:41 +0000
3+++ loco_directory/teams/models.py 2011-06-29 16:13:46 +0000
4@@ -34,11 +34,12 @@
5
6 @property
7 def related_venues(self):
8- return flat_list([list(a.related_venues) for a in self.related_countries])
9+ from venues.models import Venue
10+ return Venue.objects.filter(country__continents=self)
11
12 @property
13 def related_teams(self):
14- return set(flat_list([list(a.related_teams) for a in self.related_countries]))
15+ return Team.objects.filter(countries__continents=self)
16
17 class Country(models.Model):
18 name = models.TextField(_("Name"), max_length=100)
19@@ -62,12 +63,16 @@
20 return Country.objects.filter(continents__isnull=True)
21
22 def countries_without_continent_have_venues():
23- list_of_venues = [list(a.related_venues) for a in countries_without_continent()]
24- return len(flat_list(list_of_venues))>0
25+ for country in countries_without_continent():
26+ if country.venue_set.count() > 0:
27+ return True
28+ return False
29
30 def countries_without_continent_have_teams():
31- list_of_teams = [list(a.related_teams) for a in countries_without_continent()]
32- return len(flat_list(list_of_teams))>0
33+ for country in countries_without_continent():
34+ if country.team_set.count() > 0:
35+ return True
36+ return False
37
38 class Team(models.Model, LocalTimeMixin):
39 lp_name = models.CharField(_("Launchpad Team ID"), max_length=40, null=True)
40
41=== modified file 'loco_directory/teams/views.py'
42--- loco_directory/teams/views.py 2011-06-17 22:09:01 +0000
43+++ loco_directory/teams/views.py 2011-06-29 16:13:46 +0000
44@@ -65,10 +65,8 @@
45 return response
46
47 def team_list(request):
48- team_list = Team.objects.all().order_by('name')
49
50 context = {
51- 'team_list': team_list,
52 'continents': Continent.objects.all().order_by('name'),
53 'countries_without_continent': countries_without_continent().order_by('name'),
54 'countries_without_continent_have_teams': countries_without_continent_have_teams(),
55
56=== modified file 'loco_directory/templates/teams/team_list.html'
57--- loco_directory/templates/teams/team_list.html 2010-11-20 17:25:50 +0000
58+++ loco_directory/templates/teams/team_list.html 2011-06-29 16:13:46 +0000
59@@ -11,7 +11,7 @@
60 {% endblock %}
61
62 {% block content %}
63-{% if team_list %}
64+
65 {% for continent in continents %}{% if continent.related_teams %}
66 <article class="main-content">
67 <h2><a name="{{continent.name}}">{{continent.name}}</a></h2>
68@@ -53,7 +53,5 @@
69 <br class="clear" />
70 </article>
71 {% endif %}
72-{% endif %}
73-
74
75 {% endblock %}

Subscribers

People subscribed via source and target branches