-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fix connection #29
base: master
Are you sure you want to change the base?
Fix connection #29
Conversation
…tead of create a connection per sharded model
let(:connection_names) { ["primary", "ShardForTestUser001", "ShardForTestUser002", "ShardForTestUser003", "SequencerForTestUserSequencer"] } | ||
|
||
it "Create 1 connection for each DB" do | ||
expect(ActiveRecord::Base.connection_handler.connection_pool_list.map{|c| c.spec.name }).to match_array(connection_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Layout/SpaceInsideBlockBraces: Space between { and | missing.
@@ -35,6 +37,14 @@ def find_from_all_by_name(name) | |||
|
|||
let(:alice) { model.put! name: "Alice" } | |||
|
|||
context "ActiveRecord::ConnectionAdapters::ConnectionPool" do | |||
let(:connection_names) { ["primary", "ShardForTestUser001", "ShardForTestUser002", "ShardForTestUser003", "SequencerForTestUserSequencer"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/WordArray: Use %w or %W for an array of words.
end | ||
a_class.class_eval { abstract_class = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UselessAssignment: Useless assignment to variable - abstract_class.
@@ -1,3 +1,14 @@ | |||
module EstablishConnectionForShard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
Thank you for feedback. I want to think for redesign modules. |
Thank you for review. |
establish_connection
store the connection to ConnectionPool with name of called class name.So, original code was creating connections for each sharded model.
I fixed that use same ConnectionPool for same DB.
This fix decrease connection count to the DB.