aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/transactions.rb
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Merge pull request #6226 from gnufied/master"Rafael Mendonça França2013-04-101-2/+6
| | | | | | | | | | | | | This reverts commit 9bf1a0db4acbbf9e8e6f707250269185224e7efe, reversing changes made to fed97091b9546d369a240d10b184793d49247dd3. Conflicts: activerecord/test/cases/transaction_callbacks_test.rb Reason: This fix introduces another issue described at #8937, so we are reverting it to restore the behavior of 3-2-stable. We will fix both issues when we come out with a better solution
* SQLite3 3.6.8+ supports nested transactions [ci skip]Neeraj Singh2013-03-181-1/+1
| | | | | http://www.sqlite.org/lang_savepoint.html https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L130-L132
* multiple actions for :on option with `after_commit` and `after_rollback`Yves Senn2013-02-211-14/+17
| | | | Closes #988.
* Don't call after_commit when creating through an association and save fails, ↵James Miller2013-02-131-1/+4
| | | | fixes #5802
* validate :on option on after_commit and after_rollback callbacksPascal Friederich2012-12-261-6/+16
|
* 1.9 Syntax related changesAvnerCohen2012-11-101-14/+14
|
* frozen state should be restored after txn is abortedAaron Patterson2012-10-221-2/+3
|
* Fix out-of-date URL.Alex Reisner2012-09-191-1/+1
|
* Revert "create a transaction object and point AR objects at that object ↵Jon Leighton2012-09-151-29/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | during a" This reverts commit c24c885209ac2334dc6f798c394a821ee270bec6. Here's the explanation I just sent to @tenderlove: Hey, I've been thinking about about the transaction memory leak thing that we were discussing. Example code: post = nil Post.transaction do N.times { post = Post.create } end Post.transaction is going to create a real transaction and there will also be a (savepoint) transaction inside each Post.create. In an idea world, we'd like all but the last Post instance to be GC'd, and for the last Post instance to receive its after_commit callback when Post.transaction returns. I can't see how this can work using your solution where the Post itself holds a reference to the transaction it is in; when Post.transaction returns, control does not switch to any of Post's instance methods, so it can't trigger the callbacks itself. What we really want is for the transaction itself to hold weak references to the objects within the transaction. So those objects can be GC'd, but if they are not GC'd then the transaction can iterate them and execute their callbacks. I've looked into WeakRef implementations that are available. On 1.9.3, the stdlib weakref library is broken and we shouldn't use it. There is a better implementation here: https://github.com/bdurand/ref/blob/master/lib/ref/weak_reference/pure_ruby.rb We could use that, either by pulling in the gem or just copying the code in, but it still suffers from the limitation that it uses ObjectSpace finalizers. In my testing, this finalizers make GC quite expensive: https://gist.github.com/3722432 Ruby 2.0 will have a native WeakRef implementation (via ObjectSpace::WeakMap), hence won't be reliant on finalizers: http://bugs.ruby-lang.org/issues/4168 So the ultimate solution will be for everyone to use Ruby 2.0, and for us to just use ObjectSpace::WeakMap. In the meantime, we have basically 3 options: The first is to leave it as it is. The second is to use a finalizer-based weakref implementation and take the GC perf hit. The final option is to store object ids rather than the actual objects. Then use ObjectSpace._id2ref to deference the objects at the end of the transaction, if they exist. This won't stop memory use growing within the transaction, but it'll grow more slowly. I benchmarked the performance of _id2ref this if the object does or does not exist: https://gist.github.com/3722550 If it does exist it seems decent, but it's hugely more expensive if it doesn't, probably because we have to do the rescue nil. Probably most of the time the objects will exist. However the point of doing this optimisation is to allow people to create a large number of objects inside a transaction and have them be GC'd. So for that use case, we'd be replacing one problem with another. I'm not sure which of the two problems is worse. My feeling is that we should just leave this for now and come back to it when Ruby 2.0 is out. I'm going to revert your commit because I can't see how it solves this. Hope you don't mind... if I've misunderstood then let me know! Jon
* create a transaction object and point AR objects at that object during aAaron Patterson2012-09-071-6/+29
| | | | transaction.
* documents after_(commit|rollback)Xavier Noria2012-08-301-0/+18
|
* ivar will always be defined, so stop checkingAaron Patterson2012-08-231-3/+1
|
* initialize instance variables for transactions to remove conditionalsAaron Patterson2012-08-201-8/+6
|
* fix whitespace errorsAaron Patterson2012-08-201-2/+2
|
* Restore state on create when ActiveRecord::RecordInvalid is raisedDave Yeu2012-08-111-1/+1
| | | | This fixes issue #3217.
* Restore the frozen state on rollback. Fixes #6417.Godfrey Chan2012-05-211-1/+3
| | | | | | | | | | | | | | | | | | | | Currently, when saving a frozen record, an exception would be thrown which causes a rollback. However, there is a bug in active record that "defrost" the record as a side effect: >> t = Topic.new => #<Topic id: nil, ...> >> t.freeze => #<Topic id: nil, ...> >> t.save RuntimeError: can't modify a frozen Hash >> t.frozen? => false >> t.save => true This patch fixes the bug by explictly restoring the frozen state on the attributes Hash after every rollback.
* Merge pull request #5535 from markmcspadden/issue_5527_rollbacksAaron Patterson2012-05-161-1/+9
|\ | | | | Allow manual rollbacks in after_save to reset object correctly
| * Allow manual rollbacks in after_save to reset object correctlyMark McSpadden2012-03-211-1/+9
| |
* | Fix transaction state not changing when after record gets commitedHemant Kumar2012-05-091-6/+2
|/
* Remove IdentityMapCarlos Antonio da Silva2012-03-131-2/+0
|
* Remove Array.wrap calls in ActiveRecordRafael Mendonça França2012-01-061-2/+2
|
* fix nodocsVijay Dev2011-12-091-5/+5
|
* Revert "Raise error on unknown primary key."Jon Leighton2011-10-051-1/+1
| | | | This reverts commit ee2be435b1e5c0e94a4ee93a1a310e0471a77d07.
* Raise error on unknown primary key.Jon Leighton2011-10-051-1/+1
| | | | | If we don't have a primary key when we ask for it, it's better to fail fast. Fixes GH #2307.
* Edited activerecord/lib/active_record/transactions.rb via GitHubAyose2011-06-011-1/+1
|
* The URL http://dev.mysql.com/doc/refman/5.0/en/savepoints.html is no longer ↵Ayose2011-06-011-1/+1
| | | | available
* Use IM when trying to load records using ID.Emilio Tagua2011-04-041-0/+1
| | | | Signed-off-by: José Valim <jose.valim@gmail.com>
* Merge remote branch 'rails/master' into identity_mapEmilio Tagua2011-02-151-13/+11
|\ | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/examples/performance.rb activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/associations/association_proxy.rb activerecord/lib/active_record/autosave_association.rb activerecord/lib/active_record/base.rb activerecord/lib/active_record/nested_attributes.rb activerecord/test/cases/relations_test.rb
| * Use run_callbacks; the generated _run_<name>_callbacks method is not a ↵John Firebaugh2011-01-311-2/+2
| | | | | | | | | | | | public interface. Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
| * remove useless conditionalAaron Patterson2011-01-171-10/+8
| |
| * Allow primary_key to be an attribute when the model is a new recordSantiago Pastorino2010-12-281-2/+2
| |
* | Merge remote branch 'rails/master' into identity_mapEmilio Tagua2010-12-201-15/+19
|\| | | | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/associations/association_proxy.rb activerecord/lib/active_record/autosave_association.rb activerecord/lib/active_record/base.rb activerecord/lib/active_record/persistence.rb
| * reviews commit 53bbbccXavier Noria2010-12-111-9/+11
| |
| * Fix doc about nested transaction rollbackIvan Evtukhovich2010-12-091-1/+2
| | | | | | | | | | Because AR::Rollback do not reraise and inner transaction is not "real" nothing rollback at all
| * Partialy revert f1c13b0dd7b22b5f6289ca1a09f1d7a8c7c8584bJosé Valim2010-11-281-7/+8
| |
* | Remove object from identity map if transaction failed.Emilio Tagua2010-11-191-0/+1
|/
* Don't check if persisted is defined just initialize it properlySantiago Pastorino2010-11-091-1/+0
|
* use persisted? instead of new_record? wherever possibleDavid Chelimsky2010-11-091-6/+7
| | | | | | | | | | | - persisted? is the API defined in ActiveModel - makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord [#5927 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* #transaction on the instance level should take options as wellCarl Lerche2010-10-141-2/+2
|
* Merge remote branch 'rails/master'Xavier Noria2010-06-201-0/+1
|\ | | | | | | | | Conflicts: actionpack/lib/abstract_controller/base.rb
| * Fix bug with rolling back frozen attributes.Brian Durand2010-06-181-0/+1
| | | | | | | | | | | | [#2991] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* | Adds title to the rest of the files in activerecord/libRizwan Reza2010-06-161-2/+4
|/
* Make logic for after_commit and after_rollback :on option work like it does ↵Brian Durand2010-06-081-18/+33
| | | | | | | | for validation callbacks. [#2991 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Revert "Temporarily revert "Update after_commit and after_rollback docs and ↵Jeremy Kemper2010-06-081-9/+109
| | | | | | | | tests to use new style API with an :on options instead of on_* suffix." and "Add after_commit and after_rollback callbacks to ActiveRecord that are called after transactions either commit or rollback on all records saved or destroyed in the transaction."" This reverts commit 1b2941cba1165b0721f57524645fe378bee2a950. [#2991]
* Temporarily revert "Update after_commit and after_rollback docs and tests to ↵Jeremy Kemper2010-06-081-109/+9
| | | | | | | | | | | | | | use new style API with an :on options instead of on_* suffix." and "Add after_commit and after_rollback callbacks to ActiveRecord that are called after transactions either commit or rollback on all records saved or destroyed in the transaction." This reverts commits d2a49e4b1f30c5997e169110eed94a55aee53f56 and da840d13da865331297d5287391231b1ed39721b. [#2991] Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/transactions.rb activerecord/test/cases/transaction_callbacks_test.rb
* eliminate alias_method_chain from ActiveRecordwycats2010-05-091-12/+10
|
* edit pass in the transactions preamble rdocXavier Noria2010-05-021-24/+31
|
* after_(commit|rollback) rdoc, edit passXavier Noria2010-04-301-5/+5
|
* Update after_commit and after_rollback docs and tests to use new style API ↵Brian Durand2010-04-291-5/+0
| | | | | | | | with an :on options instead of on_* suffix. [#2991] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Add after_commit and after_rollback callbacks to ActiveRecord that are ↵Brian Durand2010-04-291-14/+117
| | | | | | | | called after transactions either commit or rollback on all records saved or destroyed in the transaction. [#2991 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>