mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36375 from kamipo/fast_save
Avoid making extra 5 arrays in each `save`
This commit is contained in:
commit
f7396f98be
1 changed files with 28 additions and 18 deletions
|
@ -59,19 +59,26 @@ module ActiveRecord
|
|||
attribute_names.index_with(time || current_time_from_proper_timezone)
|
||||
end
|
||||
|
||||
def timestamp_attributes_for_create_in_model
|
||||
@timestamp_attributes_for_create_in_model ||=
|
||||
(timestamp_attributes_for_create & column_names).freeze
|
||||
end
|
||||
|
||||
def timestamp_attributes_for_update_in_model
|
||||
@timestamp_attributes_for_update_in_model ||=
|
||||
(timestamp_attributes_for_update & column_names).freeze
|
||||
end
|
||||
|
||||
def all_timestamp_attributes_in_model
|
||||
@all_timestamp_attributes_in_model ||=
|
||||
(timestamp_attributes_for_create_in_model + timestamp_attributes_for_update_in_model).freeze
|
||||
end
|
||||
|
||||
def current_time_from_proper_timezone
|
||||
default_timezone == :utc ? Time.now.utc : Time.now
|
||||
end
|
||||
|
||||
private
|
||||
def timestamp_attributes_for_create_in_model
|
||||
timestamp_attributes_for_create.select { |c| column_names.include?(c) }
|
||||
end
|
||||
|
||||
def timestamp_attributes_for_update_in_model
|
||||
timestamp_attributes_for_update.select { |c| column_names.include?(c) }
|
||||
end
|
||||
|
||||
def all_timestamp_attributes_in_model
|
||||
timestamp_attributes_for_create_in_model + timestamp_attributes_for_update_in_model
|
||||
end
|
||||
|
||||
def timestamp_attributes_for_create
|
||||
["created_at", "created_on"]
|
||||
end
|
||||
|
@ -80,8 +87,11 @@ module ActiveRecord
|
|||
["updated_at", "updated_on"]
|
||||
end
|
||||
|
||||
def current_time_from_proper_timezone
|
||||
default_timezone == :utc ? Time.now.utc : Time.now
|
||||
def reload_schema_from_cache
|
||||
@timestamp_attributes_for_create_in_model = nil
|
||||
@timestamp_attributes_for_update_in_model = nil
|
||||
@all_timestamp_attributes_in_model = nil
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -124,19 +134,19 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def timestamp_attributes_for_create_in_model
|
||||
self.class.send(:timestamp_attributes_for_create_in_model)
|
||||
self.class.timestamp_attributes_for_create_in_model
|
||||
end
|
||||
|
||||
def timestamp_attributes_for_update_in_model
|
||||
self.class.send(:timestamp_attributes_for_update_in_model)
|
||||
self.class.timestamp_attributes_for_update_in_model
|
||||
end
|
||||
|
||||
def all_timestamp_attributes_in_model
|
||||
self.class.send(:all_timestamp_attributes_in_model)
|
||||
self.class.all_timestamp_attributes_in_model
|
||||
end
|
||||
|
||||
def current_time_from_proper_timezone
|
||||
self.class.send(:current_time_from_proper_timezone)
|
||||
self.class.current_time_from_proper_timezone
|
||||
end
|
||||
|
||||
def max_updated_column_timestamp
|
||||
|
|
Loading…
Reference in a new issue