1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Revert "Use active record cache when available"

This reverts commit a27d692656.

The reason for reverting is that this middleware has no effect. In Rails
5.0+, Sidekiq runs its jobs using the Rails reloader/executor API[1].

In Rails 5.0+, however, the ActiveRecord query cache registers its own
hooks with the executor[2], and these hooks automatically enable the
query cache for the duration of any work the executor performs[3].

As a result, the query cache is already on by default for any Sidekiq
jobs run in Rails 5.0+, so it's not necessary to separately enable it in
a middleware.

[1] eca6acc0ce/lib/sidekiq/rails.rb (L33-L37)
[2] f8c00c1300/activerecord/lib/active_record/railtie.rb (L159-L163)
[3] f8c00c1300/activerecord/lib/active_record/query_cache.rb (L26-L41)
This commit is contained in:
Simon Coffey 2018-02-15 14:16:54 +00:00 committed by Mike Perham
parent eca6acc0ce
commit abca42db3c
2 changed files with 4 additions and 20 deletions

View file

@ -1,11 +0,0 @@
module Sidekiq
module Middleware
module Server
class ActiveRecordCache
def call(*args, &block)
::ActiveRecord::Base.cache(&block)
end
end
end
end
end

View file

@ -9,15 +9,10 @@ module Sidekiq
# class block. Definitely before config/environments/*.rb and
# config/initializers/*.rb.
config.before_configuration do
if defined?(::ActiveRecord)
if ::Rails::VERSION::MAJOR < 5 && defined?(::ActiveRecord)
Sidekiq.server_middleware do |chain|
if ::Rails::VERSION::MAJOR < 5
require 'sidekiq/middleware/server/active_record'
chain.add Sidekiq::Middleware::Server::ActiveRecord
end
require 'sidekiq/middleware/server/active_record_cache'
chain.add Sidekiq::Middleware::Server::ActiveRecordCache
require 'sidekiq/middleware/server/active_record'
chain.add Sidekiq::Middleware::Server::ActiveRecord
end
end
end
@ -59,4 +54,4 @@ if defined?(::Rails) && ::Rails::VERSION::MAJOR < 4
$stderr.puts("**************************************************")
$stderr.puts("⛔️ WARNING: Sidekiq server is no longer supported by Rails 3.2 - please ensure your server/workers are updated")
$stderr.puts("**************************************************")
end
end