switchman 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2f68441314d99fc739f03cd1af70e938efa0d0803ff6f5c405aed15afea0798
4
- data.tar.gz: 553846718daea03d833792d3ff079ee0ce2bddce63231f2e40262fe901c84949
3
+ metadata.gz: 730c18de3f2e731bbbdce7ff8405691a0530510fa62ef552ae526728c92f1572
4
+ data.tar.gz: 8fbf3a6f789e76816e08af306404c8c5f04be944d4525289be82d00502c2df34
5
5
  SHA512:
6
- metadata.gz: 4d05aea36873a2d809b414ad9cceeb8e1ee3c0966acd7e67e3f941e3b971c685a3a7ad666d19b5a74edc47ba59025782a486c70c596d918998ef01a01c5b9f40
7
- data.tar.gz: 02bb3d231398cae6966ec6d8f1ca5ce4101f529d55dc119ebcbd512077ab3c5887c3eb9309fc5a8aba2df7fcd5eb21fae9911c1c2b4c29cfc328653a52fa3d1f
6
+ metadata.gz: bf7bafe9382647ce00b1323c168ce49f48d5d8d7db68718d75a9a05f6c4f02557e439aa941b9876273c962936891c757f89422727a50ff4ec4a5a045e40b6e23
7
+ data.tar.gz: c84822183e7448b8a9b2db7c9400d91429756e2b2f470fd1183a68e0d914b448cc1afb97ae3981fdf21a4a6f82c1eefb959d19fa801d4ac78120d8d31e300790
@@ -254,7 +254,21 @@ module Switchman
254
254
  pid, io_in, io_out, io_err = Open4.pfork4(lambda do
255
255
  begin
256
256
  Switchman.config[:on_fork_proc]&.call
257
- $0 = [$0, ARGV, name].flatten.join(' ')
257
+
258
+ # set a pretty name for the process title, up to 128 characters
259
+ # (we don't actually know the limit, depending on how the process
260
+ # was started)
261
+ # first, simplify the binary name by stripping directories,
262
+ # then truncate arguments as necessary
263
+ bin = File.basename($0) # Process.argv0 doesn't work on Ruby 2.5 (https://bugs.ruby-lang.org/issues/15887)
264
+ max_length = 128 - bin.length - name.length - 3
265
+ args = ARGV.join(" ")
266
+ if max_length >= 0
267
+ args = args[0..max_length]
268
+ end
269
+ new_title = [bin, args, name].join(" ")
270
+ Process.setproctitle(new_title)
271
+
258
272
  with_each_shard(subscope, categories, options) { yield }
259
273
  exception_pipe.last.close
260
274
  rescue => e
@@ -76,15 +76,30 @@ module Switchman
76
76
 
77
77
  module Preloader
78
78
  module Association
79
- if ::Rails.version >= "5.2"
79
+ if ::Rails.version >= "5.2" and ::Rails.version < "6.0"
80
80
  def run(preloader)
81
- # TODO - can move associated_records_by_owner into this after 5.1 is gonzo
82
81
  associated_records_by_owner(preloader).each do |owner, records|
83
82
  associate_records_to_owner(owner, records)
84
83
  end
85
84
  end
86
85
  end
87
86
 
87
+ if ::Rails.version >= "6.0"
88
+ # Copypasta from Activerecord but with added global_id_for goodness.
89
+ def records_for(ids)
90
+ scope.where(association_key_name => ids).load do |record|
91
+ global_key = Shard.global_id_for(record[association_key_name], record.shard)
92
+ owner = owners_by_key[global_key.to_s].first
93
+ association = owner.association(reflection.name)
94
+ association.set_inverse_instance(record)
95
+ end
96
+ end
97
+
98
+ def records_by_owner
99
+ associated_records_by_owner
100
+ end
101
+ end
102
+
88
103
  def associated_records_by_owner(preloader = nil)
89
104
  owners_map = owners_by_key
90
105
 
@@ -121,7 +121,9 @@ module Switchman
121
121
  group_fields = group_attrs
122
122
  end
123
123
 
124
- group_aliases = group_fields.map { |field| column_alias_for(field) }
124
+ # .clone below corrects for what I consider a Rails bug. column_alias_for modifies the string in place.
125
+ # to_s is because Rails 5 returns a string but Rails 6 returns a symbol.
126
+ group_aliases = group_fields.map { |field| column_alias_for(field.clone).to_s }
125
127
  group_columns = group_aliases.zip(group_fields).map { |aliaz, field|
126
128
  [aliaz, type_for(field), column_name_for(field)]
127
129
  }
@@ -161,12 +161,13 @@ module Switchman
161
161
 
162
162
  def quote_local_table_name(name)
163
163
  # postgres quotes tables and columns the same; just pass through
164
- # (differs from quote_table_name below by no logic to explicitly
165
- # qualify the table)
164
+ # (differs from quote_table_name_with_shard below by no logic to
165
+ # explicitly qualify the table)
166
166
  quote_column_name(name)
167
167
  end
168
168
 
169
- def quote_table_name name
169
+ def quote_table_name(name)
170
+ return quote_local_table_name(name) if @use_local_table_name
170
171
  name = ::ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(name.to_s)
171
172
  if !name.schema && use_qualified_names?
172
173
  name.instance_variable_set(:@schema, shard.name)
@@ -174,6 +175,13 @@ module Switchman
174
175
  name.quoted
175
176
  end
176
177
 
178
+ def with_local_table_name
179
+ @use_local_table_name = true
180
+ yield
181
+ ensure
182
+ @use_local_table_name = false
183
+ end
184
+
177
185
  def foreign_keys(table_name)
178
186
  schema = shard.name if use_qualified_names?
179
187
 
@@ -224,21 +224,11 @@ module Switchman
224
224
  end
225
225
 
226
226
  def arel_columns(columns)
227
- columns.flat_map do |field|
228
- if (Symbol === field || String === field) && (klass.has_attribute?(field) || klass.attribute_alias?(field)) && !from_clause.value
229
- klass.arel_attribute(field, table)
230
- elsif (Symbol === field || String === field) && columns_hash.key?(field.to_s) && !from_value
231
- arel_table[field]
232
- elsif Symbol === field
233
- # the rest of this is pulled from AR - the only change is from quote_table_name to quote_column_name here
234
- # otherwise qualified names will add the schema to a column
235
- connection.quote_column_name(field.to_s)
236
- elsif Proc === field
237
- field.call
238
- else
239
- field
240
- end
241
- end
227
+ connection.with_local_table_name { super }
228
+ end
229
+
230
+ def arel_column(columns)
231
+ connection.with_local_table_name { super }
242
232
  end
243
233
 
244
234
  # semi-private
@@ -40,8 +40,14 @@ module Switchman
40
40
  def database_servers
41
41
  unless @database_servers
42
42
  @database_servers = {}.with_indifferent_access
43
- ::ActiveRecord::Base.configurations.each do |(id, config)|
44
- @database_servers[id] = DatabaseServer.new(id, config)
43
+ if ::Rails.version >= '6.0'
44
+ ::ActiveRecord::Base.configurations.configurations.each do |config|
45
+ @database_servers[config.env_name] = DatabaseServer.new(config.env_name, config.config)
46
+ end
47
+ else
48
+ ::ActiveRecord::Base.configurations.each do |(id, config)|
49
+ @database_servers[id] = DatabaseServer.new(id, config)
50
+ end
45
51
  end
46
52
  end
47
53
  @database_servers
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.13.0"
2
+ VERSION = "1.14.0"
3
3
  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: 1.13.0
4
+ version: 1.14.0
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: 2019-02-27 00:00:00.000000000 Z
13
+ date: 2019-06-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '5.0'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '5.3'
24
+ version: '6.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: '5.0'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.3'
34
+ version: '6.1'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activerecord
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -41,7 +41,7 @@ dependencies:
41
41
  version: '5.0'
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '5.3'
44
+ version: '6.1'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
@@ -51,21 +51,21 @@ dependencies:
51
51
  version: '5.0'
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.3'
54
+ version: '6.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: shackles
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: 1.4.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: 1.4.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: open4
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -238,14 +238,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
238
  requirements:
239
239
  - - ">="
240
240
  - !ruby/object:Gem::Version
241
- version: '2.3'
241
+ version: '2.4'
242
242
  required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  requirements:
244
244
  - - ">="
245
245
  - !ruby/object:Gem::Version
246
246
  version: '0'
247
247
  requirements: []
248
- rubygems_version: 3.0.1
248
+ rubygems_version: 3.0.3
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: Rails 4 sharding magic