diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-03-16 17:57:27 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2012-03-16 21:20:14 +0100 |
commit | 1eff10fa0fbb93bf5669bbd09cb6e2ac6ad24813 (patch) | |
tree | 26cd3c2869cd4ffb1b1d37bd4bf751e0c5f08f63 /mediagoblin/listings | |
parent | 1b4d9edaef6d9b5650c4e54f82059f965ef75a31 (diff) | |
download | mediagoblin-1eff10fa0fbb93bf5669bbd09cb6e2ac6ad24813.tar.lz mediagoblin-1eff10fa0fbb93bf5669bbd09cb6e2ac6ad24813.tar.xz mediagoblin-1eff10fa0fbb93bf5669bbd09cb6e2ac6ad24813.zip |
More efficient first element fetching and Dot-Notation.
_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.
Diffstat (limited to 'mediagoblin/listings')
-rw-r--r-- | mediagoblin/listings/views.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 73a0feb3..d96b9606 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -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 |