Git Product home page Git Product logo

after_commit_queue's People

Contributors

bartkozal avatar jhosteny avatar mkwiatkowski avatar tism avatar wijet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

after_commit_queue's Issues

Doesn't work for nested transactions

after_commit_queue doesn't seem to work for nested transactions, as it stores its queue within the model object and ActiveRecord only runs the after_commit hook once for each uniq record. See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L80-L89
Thus, if an individual record is updated twice within a single transaction, the run_after_commit runs only once. Compare this overly simplified example:

class MyModel ...
  after_save do
    run_after_commit { puts "run after commit called" }
  end
end

MyModel.transaction do
  model1 = MyModel.find(1)
  model1.title = "1"
  model1.save!

  model2 = MyModel.find(1) # same "record"
  model2.title = "2"
  model2.save!
end

Output is only a single:

run after commit called

If we'd instead save the queue within the transaction object.

module AfterCommitQueue
  # ...

  def after_commit_queue
    self.class.connection.current_transaction.instance_variable_get("@run_after_commit_queue") || self.class.connection.current_transaction.instance_variable_set("@run_after_commit_queue", []) 
  end 

  def clear_after_commit_queue
    self.class.connection.current_transaction.instance_variable_set "@run_after_commit_queue", []
  end
end

It would work as IMO expected. What do you think?

Release a Rails 4.0 compatible gem

Hi,

I would like to suggest releasing a new version that is compatible with Rails 4.0. Bundling from GitHub ist ok, but it would be nice to get a „good“ version from rubygems.

Thanks!

Encoding problems when installing gem

When using gem like this

Gemfile

source :rubygems
gem 'after_commit_queue', :git => 'git://github.com/Ragnarson/after_commit_queue.git'

Generates

ArgumentError: invalid byte sequence in US-ASCII
An error occured while installing after_commit_queue (0.0.2), and Bundler cannot continue.
Make sure that `gem install after_commit_queue -v '0.0.2'` succeeds before bundling.

Extracted from #2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.