]> git.decadent.org.uk Git - memories.git/blobdiff - Memories/Tag.pm
JOIN optimization.
[memories.git] / Memories / Tag.pm
index 1140185a307e45e07b328e919a463c9d4120c802..744a98a089e49af7da5fff6192c99f4cf7865a7f 100644 (file)
@@ -5,10 +5,9 @@ __PACKAGE__->columns(Essential => qw/id name/);
 
 Memories::Photo->set_sql(sorted_by_tag => q/
 SELECT photo.id as id, title, uploader, uploaded, x, y
-FROM photo, tag, tagging
+FROM photo, tagging
 WHERE tagging.photo = photo.id
-    AND tagging.tag = tag.id
-    AND tag.id = ?
+    AND tagging.tag = ?
 ORDER BY photo.uploaded DESC
 /
 );
@@ -28,7 +27,7 @@ sub view :Exported {
         $sth->finish;
         $r->{template_args}{tags} = \@tags;
     } else {
-        if (!$r->objects) {
+        if (!@{$r->objects||[]}) {
             $tag = $tags[0];
         } else {
             $tag = $r->objects->[0];