aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-09-28 17:12:28 -0400
committerSean Griffin <sean@seantheprogrammer.com>2015-10-02 08:03:11 -0400
commit07723c23a7dc570beae73c074ad37227e3e8a06e (patch)
tree442e264cad0f2c99c8402d3a7ceea73beb2dadbc /activerecord/lib/active_record/attribute
parent9db73a2591e43d1851411727d6594a72efa35663 (diff)
downloadrails-07723c23a7dc570beae73c074ad37227e3e8a06e.tar.gz
rails-07723c23a7dc570beae73c074ad37227e3e8a06e.tar.bz2
rails-07723c23a7dc570beae73c074ad37227e3e8a06e.zip
Further encapsulate dirty checking on `Attribute`
We can skip the allocation of a full `AttributeSet` by changing the semantics of how we structure things. Instead of comparing two separate `AttributeSet` objects, and `Attribute` is now a singly linked list of every change that has happened to it. Since the attribute objects are immutable, to apply the changes we simply need to copy the head of the list. It's worth noting that this causes one subtle change in the behavior of AR. When a record is saved successfully, the `before_type_cast` version of everything will be what was sent to the database. I honestly think these semantics make more sense, as we could have just as easily had the DB do `RETURNING *` and updated the record with those if we had things like timestamps implemented at the DB layer. This brings our performance closer to 4.2, but we're still not quite there.
Diffstat (limited to 'activerecord/lib/active_record/attribute')
-rw-r--r--activerecord/lib/active_record/attribute/user_provided_default.rb13
1 files changed, 2 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/attribute/user_provided_default.rb b/activerecord/lib/active_record/attribute/user_provided_default.rb
index 501590cf0e..fb8ad9163e 100644
--- a/activerecord/lib/active_record/attribute/user_provided_default.rb
+++ b/activerecord/lib/active_record/attribute/user_provided_default.rb
@@ -4,8 +4,7 @@ module ActiveRecord
class Attribute # :nodoc:
class UserProvidedDefault < FromUser
def initialize(name, value, type, database_default)
- super(name, value, type)
- @database_default = database_default
+ super(name, value, type, database_default)
end
def type_cast(value)
@@ -16,17 +15,9 @@ module ActiveRecord
end
end
- def changed_from?(old_value)
- super || changed_from?(database_default.value)
- end
-
def with_type(type)
- self.class.new(name, value_before_type_cast, type, database_default)
+ self.class.new(name, value_before_type_cast, type, original_attribute)
end
-
- protected
-
- attr_reader :database_default
end
end
end