aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorwangjohn <wangjohn@mit.edu>2013-01-24 23:42:39 -0500
committerwangjohn <wangjohn@mit.edu>2013-02-20 10:51:28 -0500
commit67d8bb963d5d51fc644d6b1ca20164efb4cee6d7 (patch)
tree7bfa8c62f8032c35de714dcde95ed3d7bef57728 /activerecord/lib/active_record/attribute_methods
parent3a0b6c8e135e268c1550f93db1b63ba27457dec2 (diff)
downloadrails-67d8bb963d5d51fc644d6b1ca20164efb4cee6d7.tar.gz
rails-67d8bb963d5d51fc644d6b1ca20164efb4cee6d7.tar.bz2
rails-67d8bb963d5d51fc644d6b1ca20164efb4cee6d7.zip
Reduced memory leak problem in transactions by lazily updating AR objects with new transaction state. If AR object has a callback, the callback will be performed immediately (non-lazily) so the transaction still has to keep records with callbacks.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index 310f1b6e75..3e454b713a 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -8,27 +8,32 @@ module ActiveRecord
# Returns this record's primary key value wrapped in an Array if one is
# available.
def to_key
+ sync_with_transaction_state
key = self.id
[key] if key
end
# Returns the primary key value.
def id
+ sync_with_transaction_state
read_attribute(self.class.primary_key)
end
# Sets the primary key value.
def id=(value)
+ sync_with_transaction_state
write_attribute(self.class.primary_key, value) if self.class.primary_key
end
# Queries the primary key value.
def id?
+ sync_with_transaction_state
query_attribute(self.class.primary_key)
end
# Returns the primary key value before type cast.
def id_before_type_cast
+ sync_with_transaction_state
read_attribute_before_type_cast(self.class.primary_key)
end