aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
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/connection_adapters
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/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/transaction.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
index 3ecef96b10..73c80a3220 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
@@ -5,7 +5,7 @@ module ActiveRecord
def initialize(connection)
@connection = connection
- @state = TransactionState.new
+ @state = TransactionState.new
end
def state
@@ -14,11 +14,13 @@ module ActiveRecord
end
class TransactionState
+ attr_accessor :parent
VALID_STATES = Set.new([:committed, :rolledback, nil])
def initialize(state = nil)
@state = state
+ @parent = nil
end
def committed?
@@ -116,7 +118,11 @@ module ActiveRecord
end
def add_record(record)
- records << record
+ if record.has_transactional_callbacks?
+ records << record
+ else
+ record.set_transaction_state(@state)
+ end
end
def rollback_records
@@ -188,8 +194,9 @@ module ActiveRecord
end
def perform_commit
+ @state.set_state(:committed)
+ @state.parent = parent.state
connection.release_savepoint
- records.each { |r| parent.add_record(r) }
end
end
end