From bfd41232be13fe7aa2774e9cddd9d509d41301e8 Mon Sep 17 00:00:00 2001 From: "Andrew S. Brown" Date: Fri, 29 Aug 2014 08:41:32 -0700 Subject: [PATCH] fetch ids without instantiating records when pluck is available --- CHANGELOG.md | 2 ++ lib/acts_as_taggable_on/taggable/collection.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da73f0608..6ad97715f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch. * [@damzcodes #577 Popular feature](https://github.com/mbleigh/acts-as-taggable-on/pull/577) * Fixes * [@twalpole Update for rails edge (4.2)] + * Performance + * [@dontfidget #587 Use pluck instead of select](https://github.com/mbleigh/acts-as-taggable-on/pull/587) ### [3.3.0 / 2014-07-08](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.2.6...v3.3.0) diff --git a/lib/acts_as_taggable_on/taggable/collection.rb b/lib/acts_as_taggable_on/taggable/collection.rb index 72d359a67..94e81b626 100644 --- a/lib/acts_as_taggable_on/taggable/collection.rb +++ b/lib/acts_as_taggable_on/taggable/collection.rb @@ -135,7 +135,7 @@ def generate_tagging_scope_in_clause(tagging_scope, table_name, primary_key) table_name_pkey = "#{table_name}.#{primary_key}" if ActsAsTaggableOn::Utils.using_mysql? # See https://github.com/mbleigh/acts-as-taggable-on/pull/457 for details - scoped_ids = select(table_name_pkey).map(&:id) + scoped_ids = select(table_name_pkey).pluck(:id) tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)", scoped_ids) else tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{safe_to_sql(select(table_name_pkey))})")