switchman 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81aeec21e056026642c6aa15bda349e97c8194212f8b79222b4581d5cb2a9909
4
- data.tar.gz: 77bfd14eaf245a399ec6a5b48a9f3106daac6df393d8c55d7dad5eae56966f15
3
+ metadata.gz: 326fba116e3a3801cdd40b47ede332a372dab86522cbeaab1a3b6b361eccce1f
4
+ data.tar.gz: 190457646d607aa444dbff867c67c5cd854817e8105efab44dd00fc782d1f21e
5
5
  SHA512:
6
- metadata.gz: bfc71a265b6aea2a48350bcce77dcdcb24cea206c2dbcd4b4e3e113f0615917b314233da2038197d394d2ae961dbc8be18f12d48ccc240d57ca96eb39d4db9e6
7
- data.tar.gz: d392e78986ef050800ad61e064c702d3cb3dc98b97e48cbf42c9a973ae52226672a33ade5944119be7365f9d7f2f17e05097e0e1f2a46b1adab27dfe5169bf87
6
+ metadata.gz: 3843b4407a36b8f7f3aff2381dc6ee2e5f886169349794e679759a6d13d96b52e96e832caf78728f20df7d1d017701d7e7d8847c8a4620cd6b669ba8f25e9cc6
7
+ data.tar.gz: 8e667cd250473f5b885fea29888454a186bafa9f694138bf0cf9f6761962ef4bf2a85b595a9cd7d26fb3f6532b4b8b8be9d6362c01329a63f94272f63ee55b4b
@@ -160,9 +160,9 @@ module Switchman
160
160
  # nothing to do
161
161
  return if database_servers.count.zero?
162
162
 
163
- scopes = database_servers.map do |server|
163
+ scopes = database_servers.to_h do |server|
164
164
  [server, server.shards.merge(scope)]
165
- end.to_h
165
+ end
166
166
  else
167
167
  scopes = scope.group_by(&:database_server)
168
168
  end
@@ -475,7 +475,7 @@ module Switchman
475
475
  end
476
476
 
477
477
  def initialize_sharding
478
- full_connects_to_hash = DatabaseServer.all.map { |db| [db.id.to_sym, db.connects_to_hash] }.to_h
478
+ full_connects_to_hash = DatabaseServer.all.to_h { |db| [db.id.to_sym, db.connects_to_hash] }
479
479
  sharded_models.each do |klass|
480
480
  connects_to_hash = full_connects_to_hash.deep_dup
481
481
  if klass == UnshardedRecord
@@ -189,7 +189,7 @@ module Switchman
189
189
  if reflection
190
190
  if reflection.options[:polymorphic]
191
191
  begin
192
- read_attribute(reflection.foreign_type)&.constantize&.connection_classes
192
+ read_attribute(reflection.foreign_type)&.constantize&.connection_classes || ::ActiveRecord::Base
193
193
  rescue NameError
194
194
  # in case someone is abusing foreign_type to not point to an actual class
195
195
  ::ActiveRecord::Base
@@ -83,7 +83,7 @@ module Switchman
83
83
  if opts[:association]
84
84
  key_ids = calculated_data.collect { |row| row[opts[:group_aliases].first] }
85
85
  key_records = opts[:association].klass.base_class.where(id: key_ids)
86
- key_records = key_records.map { |r| [Shard.relative_id_for(r, shard, target_shard), r] }.to_h
86
+ key_records = key_records.to_h { |r| [Shard.relative_id_for(r, shard, target_shard), r] }
87
87
  end
88
88
 
89
89
  calculated_data.map do |row|
@@ -89,13 +89,13 @@ module Switchman
89
89
  end
90
90
 
91
91
  def connects_to_hash
92
- self.class.all_roles.map do |role|
92
+ self.class.all_roles.to_h do |role|
93
93
  config_role = role
94
94
  config_role = :primary unless roles.include?(role)
95
95
  config_name = :"#{id}/#{config_role}"
96
96
  config_name = :primary if id == ::Rails.env && config_role == :primary
97
97
  [role.to_sym, config_name]
98
- end.to_h
98
+ end
99
99
  end
100
100
 
101
101
  def destroy
@@ -107,6 +107,11 @@ module Switchman
107
107
  raise 'Sharding did not set up correctly' if @@sharding_failed
108
108
 
109
109
  Shard.clear_cache
110
+ if use_transactional_tests
111
+ Shard.default(reload: true)
112
+ @shard1 = Shard.find(@shard1.id)
113
+ @shard2 = Shard.find(@shard2.id)
114
+ end
110
115
  end
111
116
 
112
117
  klass.after do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.0.6'
4
+ VERSION = '3.0.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-02-11 00:00:00.000000000 Z
13
+ date: 2022-02-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -298,7 +298,8 @@ files:
298
298
  homepage: http://www.instructure.com/
299
299
  licenses:
300
300
  - MIT
301
- metadata: {}
301
+ metadata:
302
+ rubygems_mfa_required: 'true'
302
303
  post_install_message:
303
304
  rdoc_options: []
304
305
  require_paths: