mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Optimize counting of has_many associations by setting the association to empty if the count is 0
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1235 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -92,13 +92,17 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def count_records
|
||||
if has_cached_counter?
|
||||
count = if has_cached_counter?
|
||||
@owner.send(:read_attribute, cached_counter_attribute_name)
|
||||
elsif @options[:counter_sql]
|
||||
@association_class.count_by_sql(@counter_sql)
|
||||
else
|
||||
@association_class.count(@counter_sql)
|
||||
end
|
||||
|
||||
@target = [] and loaded if count == 0
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
def has_cached_counter?
|
||||
|
||||
Reference in New Issue
Block a user