Skip to content
Browse files

Make Controller_Tags::get_tag_query() quicker for single tag queries.

  • Loading branch information...
1 parent 67cea2b commit 0197194368ca84ef2763016d93d60f3f90ec3e4e @shadlaws shadlaws committed Jul 16, 2013
Showing with 6 additions and 4 deletions.
  1. +6 −4 modules/tag/classes/Tag/Controller/Tags.php
View
10 modules/tag/classes/Tag/Controller/Tags.php
@@ -186,10 +186,12 @@ public function action_find_by_name() {
* @see Controller_Tags::action_show()
*/
static function get_tag_query($tags) {
- // For a single tag this would just be $tag->items->viewable(), but ORM doesn't handle
- // multi-relationships as easily. So, we query the pivot table manually. We do a "where in..."
- // which finds the items which have *any* of the tags, then require that the count be the total
- // number of tags to ensure the items have *all* of the tags.
+ if (count($tags) == 1) {
+ return $tags[0]->items->viewable();
+ }
+
+ // ORM doesn't handle multiple "has many through" relationships very easily,
+ // so we query the pivot table manually.
// @todo: try to do this in 1 query instead of 2 without tripping up count_all() and find_all().
$tag_ids = array();

0 comments on commit 0197194

Please sign in to comment.
Something went wrong with that request. Please try again.