switchman 3.3.2 → 3.3.4

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: eba3197eb56e020790a7ff144dc55f15bb9ad84f523728e70d7573aa5a778f2d
4
- data.tar.gz: e8003ce68cf4ae8262f6d40c8229c44ceb785c8313e717fca2b00edadb8e61e9
3
+ metadata.gz: 9dfbc3eb712e4dabeaf71e1772014d3fcc50f439d7266c03943050e4054791f2
4
+ data.tar.gz: 902b59d7077cab4e9c583b55e5f1c3e4df6565e678b806f7df4515033031ea65
5
5
  SHA512:
6
- metadata.gz: dd810811744c3ebe8f6dcef36c00a0c04dbaaca70aaa574a33bd9496e204c3afcd0696088fa79e500eb28cc835738d3f273bebe9fc023c86794353348e41e6be
7
- data.tar.gz: f7c6804dbb5abba70034eeae11b9cf2f77e42052fb23366a68d4b139eddfd9434ee6190f9d391112e82017187473bdc11ded1a62a474a02e113ff15d7d399a5a
6
+ metadata.gz: cba1cdfe3b5297443fe62064db702a3164fab8939497196e2c325e3a28fb6c4d1bbbd64698dd7c861c7f60b32eb5d91d6c1273ec4f8d3eafe45f675f5fcc36b1
7
+ data.tar.gz: b66c46f377262622339d18bd5167c6fca048b02e8167f9636aefae642afca1987ec51c71ed68a4fb3177fd0176c589b4f587c3336cc863f4b3478ed25503af53
@@ -273,10 +273,11 @@ module Switchman
273
273
  end
274
274
 
275
275
  module AutosaveAssociation
276
- def record_changed?(reflection, record, key)
277
- record.new_record? ||
278
- (record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key) || # have to use send instead of [] because sharding
279
- record.attribute_changed?(reflection.foreign_key)
276
+ def association_foreign_key_changed?(reflection, record, key)
277
+ return false if reflection.through_reflection?
278
+
279
+ # have to use send instead of _read_attribute because sharding
280
+ record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key
280
281
  end
281
282
 
282
283
  def save_belongs_to_association(reflection)
@@ -3,6 +3,21 @@
3
3
  module Switchman
4
4
  module ActiveRecord
5
5
  module ConnectionPool
6
+ def get_schema_cache(connection)
7
+ self.schema_cache ||= SharedSchemaCache.get_schema_cache(connection)
8
+ self.schema_cache.connection = connection
9
+
10
+ self.schema_cache
11
+ end
12
+
13
+ # rubocop:disable Naming/AccessorMethodName override method
14
+ def set_schema_cache(cache)
15
+ cache.instance_variables.each do |x|
16
+ self.schema_cache.instance_variable_set(x, cache.instance_variable_get(x))
17
+ end
18
+ end
19
+ # rubocop:enable Naming/AccessorMethodName override method
20
+
6
21
  def default_schema
7
22
  connection unless @schemas
8
23
  # default shard will not switch databases immediately, so it won't be set yet
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Switchman
4
+ class SharedSchemaCache
5
+ def self.get_schema_cache(connection)
6
+ @schema_cache ||= ::ActiveRecord::ConnectionAdapters::SchemaCache.new(connection)
7
+ @schema_cache.connection = connection
8
+ @schema_cache
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = '3.3.2'
4
+ VERSION = '3.3.4'
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.3.2
4
+ version: 3.3.4
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: 2023-02-13 00:00:00.000000000 Z
13
+ date: 2023-03-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -290,6 +290,7 @@ files:
290
290
  - lib/switchman/rails.rb
291
291
  - lib/switchman/shard.rb
292
292
  - lib/switchman/sharded_instrumenter.rb
293
+ - lib/switchman/shared_schema_cache.rb
293
294
  - lib/switchman/standard_error.rb
294
295
  - lib/switchman/test_helper.rb
295
296
  - lib/switchman/unsharded_record.rb