Permalink
Browse files

Use IdentityMap middleware to flush map on each request.

  • Loading branch information...
1 parent 4da31d2 commit f3722a30b63f45add2e6e03c4e7498b46628b60b @miloops miloops committed Oct 14, 2010
@@ -95,5 +95,17 @@ def identity_map
ActiveRecord::IdentityMap
end
end
+
+ class Middleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ @app.call(env)
+ ensure
+ ActiveRecord::IdentityMap.clear
+ end
+ end
end
end
@@ -22,6 +22,9 @@ class Railtie < Rails::Railtie
config.app_middleware.insert_after "::ActionDispatch::Callbacks",
"ActiveRecord::ConnectionAdapters::ConnectionManagement"
+ config.app_middleware.insert_after "::ActionDispatch::Callbacks",
+ "ActiveRecord::IdentityMap::Middleware"
+
rake_tasks do
load "active_record/railties/databases.rake"
end
@@ -166,7 +166,7 @@ def from_bar_helper
require "#{app_path}/config/environment"
- expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
+ expects = [ActiveRecord::IdentityMap::Middleware, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
@@ -28,6 +28,7 @@ def app
"ActionDispatch::RemoteIp",
"Rack::Sendfile",
"ActionDispatch::Callbacks",
+ "ActiveRecord::IdentityMap::Middleware",
"ActiveRecord::ConnectionAdapters::ConnectionManagement",
"ActiveRecord::QueryCache",
"ActionDispatch::Cookies",
@@ -55,6 +56,7 @@ def app
boot!
assert !middleware.include?("ActiveRecord::ConnectionAdapters::ConnectionManagement")
assert !middleware.include?("ActiveRecord::QueryCache")
+ assert !middleware.include?("ActiveRecord::IdentityMap::Middleware")
end
test "removes lock if allow concurrency is set" do

0 comments on commit f3722a3

Please sign in to comment.