diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-11-19 14:10:21 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-11-19 14:11:29 +0000 |
commit | fec85cf10d831ab90386a549ea558b0dd58a813f (patch) | |
tree | 9ac2eee15c1531107fe0b14d95714aa6197c42a8 /activerecord | |
parent | 2ef4947ab0da304f6e5158cf89059c94e9ce0a4c (diff) | |
download | rails-fec85cf10d831ab90386a549ea558b0dd58a813f.tar.gz rails-fec85cf10d831ab90386a549ea558b0dd58a813f.tar.bz2 rails-fec85cf10d831ab90386a549ea558b0dd58a813f.zip |
Perf fix
If we're deleting all records in an association, don't add a IN(..)
clause to the query.
Fixes #3672.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 00014f858c..c50229e779 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -67,6 +67,11 @@ ## Rails 3.1.3 (unreleased) ## +* Perf fix: If we're deleting all records in an association, don't add a IN(..) clause + to the query. *GH 3672* + + *Jon Leighton* + * Fix bug with referencing other mysql databases in set_table_name. *GH 3690* * Fix performance bug with mysql databases on a server with lots of other databses. *GH 3678* diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 50ee60284c..3353cdf1ef 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -89,8 +89,12 @@ module ActiveRecord records.each { |r| r.destroy } update_counter(-records.length) unless inverse_updates_counter_cache? else - keys = records.map { |r| r[reflection.association_primary_key] } - scope = scoped.where(reflection.association_primary_key => keys) + scope = scoped + + unless records == load_target + keys = records.map { |r| r[reflection.association_primary_key] } + scope = scoped.where(reflection.association_primary_key => keys) + end if method == :delete_all update_counter(-scope.delete_all) |