Michael Hall has proposed merging 
lp:~mhall119/loco-directory/speed-up-teams-list into lp:loco-directory.

Requested reviews:
  loco-directory-dev (loco-directory-dev)

For more details, see:
https://code.launchpad.net/~mhall119/loco-directory/speed-up-teams-list/+merge/66342

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.
-- 
https://code.launchpad.net/~mhall119/loco-directory/speed-up-teams-list/+merge/66342
Your team loco-directory-dev is requested to review the proposed merge of 
lp:~mhall119/loco-directory/speed-up-teams-list into lp:loco-directory.
=== modified file 'loco_directory/teams/models.py'
--- loco_directory/teams/models.py	2011-06-17 17:10:41 +0000
+++ loco_directory/teams/models.py	2011-06-29 16:13:46 +0000
@@ -34,11 +34,12 @@
 
     @property
     def related_venues(self):
-        return flat_list([list(a.related_venues) for a in self.related_countries])
+        from venues.models import Venue
+        return Venue.objects.filter(country__continents=self)
     
     @property
     def related_teams(self):
-        return set(flat_list([list(a.related_teams) for a in self.related_countries]))
+        return Team.objects.filter(countries__continents=self)
 
 class Country(models.Model):
     name = models.TextField(_("Name"), max_length=100)
@@ -62,12 +63,16 @@
     return Country.objects.filter(continents__isnull=True)
 
 def countries_without_continent_have_venues():
-    list_of_venues = [list(a.related_venues) for a in countries_without_continent()]
-    return len(flat_list(list_of_venues))>0
+    for country in countries_without_continent():
+        if country.venue_set.count() > 0:
+            return True
+    return False
 
 def countries_without_continent_have_teams():
-    list_of_teams = [list(a.related_teams) for a in countries_without_continent()]
-    return len(flat_list(list_of_teams))>0
+    for country in countries_without_continent():
+        if country.team_set.count() > 0:
+            return True
+    return False
 
 class Team(models.Model, LocalTimeMixin):
     lp_name = models.CharField(_("Launchpad Team ID"), max_length=40, null=True)

=== modified file 'loco_directory/teams/views.py'
--- loco_directory/teams/views.py	2011-06-17 22:09:01 +0000
+++ loco_directory/teams/views.py	2011-06-29 16:13:46 +0000
@@ -65,10 +65,8 @@
     return response
 
 def team_list(request):
-    team_list = Team.objects.all().order_by('name')
     
     context = {
-        'team_list': team_list,
         'continents': Continent.objects.all().order_by('name'),
         'countries_without_continent': countries_without_continent().order_by('name'),
         'countries_without_continent_have_teams': countries_without_continent_have_teams(),

=== modified file 'loco_directory/templates/teams/team_list.html'
--- loco_directory/templates/teams/team_list.html	2010-11-20 17:25:50 +0000
+++ loco_directory/templates/teams/team_list.html	2011-06-29 16:13:46 +0000
@@ -11,7 +11,7 @@
 {% endblock %}
 
 {% block content %}
-{% if team_list %}
+
   {% for continent in continents %}{% if continent.related_teams %}
     <article class="main-content">
       <h2><a name="{{continent.name}}">{{continent.name}}</a></h2>
@@ -53,7 +53,5 @@
     <br class="clear" />
     </article>
   {% endif %}
-{% endif %}
-
 
 {% endblock %}

_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to