Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use active record cache when available #3718

Merged
merged 1 commit into from Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/sidekiq/middleware/server/active_record_cache.rb
@@ -0,0 +1,11 @@
module Sidekiq
module Middleware
module Server
class ActiveRecordCache
def call(*args, &block)
::ActiveRecord::Base.cache(&block)
end
end
end
end
end
13 changes: 9 additions & 4 deletions lib/sidekiq/rails.rb
Expand Up @@ -9,10 +9,15 @@ class Rails < ::Rails::Engine
# class block. Definitely before config/environments/*.rb and
# config/initializers/*.rb.
config.before_configuration do
if ::Rails::VERSION::MAJOR < 5 && defined?(::ActiveRecord)
if defined?(::ActiveRecord)
Sidekiq.server_middleware do |chain|
require 'sidekiq/middleware/server/active_record'
chain.add Sidekiq::Middleware::Server::ActiveRecord
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
end
end
end
Expand Down Expand Up @@ -54,4 +59,4 @@ def inspect
$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