More efficient first element fetching and Dot-Notation.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Fri, 16 Mar 2012 16:57:27 +0000 (17:57 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Fri, 16 Mar 2012 20:20:14 +0000 (21:20 +0100)
_get_tag_name_from_entries:
1) Replace:
     if q.count():
       elem = q[0]
   by:
     for element in q:
       ...
       break

   this doesn't do two db queries but only one.

2) And another dose of Dot-Notation as usual.

mediagoblin/listings/views.py

index 73a0feb365ca8695cb60e8277d7af555255c7c6c..d96b9606040d340899222403c0a2fc6b8e52b7b7 100644 (file)
@@ -29,11 +29,13 @@ def _get_tag_name_from_entries(media_entries, tag_slug):
     """
     # ... this is slightly hacky looking :\
     tag_name = tag_slug
-    if media_entries.count():
-        for tag in media_entries[0]['tags']:
+    # if media_entries.count():
+    for entry in media_entries:
+        for tag in entry.tags:
             if tag['slug'] == tag_slug:
                 tag_name = tag['name']
                 break
+        break
 
     return tag_name