-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with non-releasing AR connections
Fixes anycable/anycable#9
- Loading branch information
Showing
6 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
module Anycable | ||
module Rails | ||
module ActiveRecord | ||
# Release ActiveRecord connection after every call (if any) | ||
module ReleaseConnection | ||
def connect(*) | ||
wrap_release_connection { super } | ||
end | ||
|
||
def disconnect(*) | ||
wrap_release_connection { super } | ||
end | ||
|
||
def command(*) | ||
wrap_release_connection { super } | ||
end | ||
|
||
def wrap_release_connection | ||
res = yield | ||
::ActiveRecord::Base.connection_pool.release_connection if | ||
::ActiveRecord::Base.connection_pool.active_connection? | ||
res | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
module Anycable | ||
module Rails | ||
class Engine < ::Rails::Engine # :nodoc: | ||
initializer "release AR connections in RPC handler" do |_app| | ||
ActiveSupport.on_load(:active_record) do | ||
require "anycable/rails/activerecord/release_connection" | ||
Anycable::RPCHandler.prepend Anycable::Rails::ActiveRecord::ReleaseConnection | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# frozen_string_literal: true | ||
module Anycable | ||
module Rails | ||
VERSION = "0.4.3" | ||
VERSION = "0.4.4" | ||
end | ||
end |