1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Lazily add Aggregations to composed_of models

`composed_of` is a fairly rare method to call on models.  This commit
adds the `Aggregations` module to models that call `composed_of` so that
models that *don't* call `composed_of` don't need to instantiate the
`aggregation_cache` hash.  This saves one hash allocation per model
instance that doesn't use `composed_of`
This commit is contained in:
Aaron Patterson 2018-06-25 14:22:32 -07:00
parent 83247916c9
commit 657060b5f8
No known key found for this signature in database
GPG key ID: 953170BCB4FFAFC6
2 changed files with 5 additions and 1 deletions

View file

@ -225,6 +225,10 @@ module ActiveRecord
def composed_of(part_id, options = {})
options.assert_valid_keys(:class_name, :mapping, :allow_nil, :constructor, :converter)
unless self < Aggregations
include Aggregations
end
name = part_id.id2name
class_name = options[:class_name] || name.camelize
mapping = options[:mapping] || [ name, name ]

View file

@ -288,6 +288,7 @@ module ActiveRecord #:nodoc:
extend Enum
extend Delegation::DelegateCache
extend CollectionCacheKey
extend Aggregations::ClassMethods
include Core
include DatabaseConfigurations
@ -314,7 +315,6 @@ module ActiveRecord #:nodoc:
include ActiveModel::SecurePassword
include AutosaveAssociation
include NestedAttributes
include Aggregations
include Transactions
include TouchLater
include NoTouching