Skip to content

Commit

Permalink
Small performance improvement for Rails 3, but not as satisfying as t…
Browse files Browse the repository at this point in the history
…aking the conditions and joins from the original scope and applying them to a new scope. Haven't found out how to do that in Rails 3.0 yet :(
  • Loading branch information
tomeric committed Jun 1, 2010
1 parent 59c2a5a commit 9385e17
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
Expand Up @@ -115,7 +115,9 @@ def all_tag_counts(options = {})
if ActiveRecord::VERSION::MAJOR >= 3
# Append the current scope to the scope, because we can't use scope(:find) in RoR 3.0 anymore:
scoped_select = "#{table_name}.#{primary_key}"
tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{select(scoped_select).to_sql})").
scoped_sql = select(scoped_select).to_sql

tagging_scope = tagging_scope.joins("JOIN (#{scoped_sql}) AS conditional_join ON conditional_join.#{primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id").
group(group_columns).
having(having)
else
Expand Down

0 comments on commit 9385e17

Please sign in to comment.