amatsuda/kaminari — pull request #374 by bf4 (2013-03-29 17:00:47+00:00)
Title: [#164] Make to_s in paginator threadsafe

Per https://github.com/amatsuda/kaminari/issues/164 and https://github.com/amatsuda/kaminari/issues/214 modifies the Paginator to_s method to be threadsafe without creating the overhead of a new thread and without changing the functionality of the code. Tested to work on ruby 1.8 and 1.9 for cruby, jruby, and rubinius.

Changes made:

* Make explicit what the paginator to_s is doing
* Add a flag to the subscriber when to suppress logging. No methods are undefined; thus, an undefined method cannot be cannot.

Notes:

* In a high-load environment, may not suppress logging consistently as desired
* At this point, threading is not necessary

Essential references I read on threading, concurrency, :

* http://yehudakatz.com/2010/08/14/threads-in-ruby-enough-already/
* http://www.ruby-forum.com/topic/172385
* http://www.slideshare.net/mperham/actors-and-threads
* http://ruby.runpaint.org/concurrency
* http://www.tutorialspoint.com/ruby/ruby_multithreading.htm
* https://github.com/roidrage/lograge/blob/master/lib/lograge/log_subscriber.rb

H/T @mperham @merbist @wycats @runpaint @headius @evanphx @brixen

Testing notes:

For JRuby, I had to enable c-extensions ( for sqlite3. I couldn't get the jdbc driver working )

I also had to have mongod running

Here are the gems I installed

gem install sqlite3 # 1.3.7 (requires c-extension support in JRuby)
gem install rails -v 3.2.3
gem install rails -v 3.0.3 # cruby 1.8 also requires rack and tzinfo installed
gem install rspec-rails # 2.13.0, rspec 2.13.1
gem install rr # 1.0.4
gem install datamapper # 1.2.0
gem install dm-rails # 1.2.1
gem install dm-sqlite-adapter # 1.2.0
gem install mongoid # 3.1.12 (not 1.8-compatible)
gem install mongoid -v 2.4.12
gem install mongo_mapper # 0.12.0
gem install sinatra sinatra-contrib # 1.3.2
gem install padrino-helpers # 0.10.7