switchman 1.14.7 → 1.14.8

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: a7f92e216d9c343ff6d8ded7ea32629a86baeeca5af8daf39dcfd4a81dc1c6af
4
- data.tar.gz: 13499b3453710700810e928e17a95a86bed24f93cd82a6eeacc57fd1032f2df9
3
+ metadata.gz: dab76e2ecd636e151a0cd1073bb2271fb54ed6051dbaecca170c89fb96de012c
4
+ data.tar.gz: f4537579439d2b6dc6ce8947edeaf80effb6af16eef20f13ef85b1e1803b80d9
5
5
  SHA512:
6
- metadata.gz: 84bf01fe033e84e715066e087e4afe832c14acb291a2248f1697313e9123643671c226aa189c7cf44e8d9ddcd765c4f54f06ac2b4c03dba53cfbeaac148816d9
7
- data.tar.gz: 23a24930bf9cf0e744d6b4c4661628af8acacf6945c768847723458278971427360eb00b3e1683c997a772f3e391857849611713685cb26e870c6d163f05bfd0
6
+ metadata.gz: a502e2f21fa54eeb1a04589ed5695b2077039ba011e2ee04fc322bfca0107ddf923b0863748c6ab08a35cc910e7f5b880d052acbddaee75149fc031e8fd0fcbd
7
+ data.tar.gz: 66bb964e5622bf09aecee7a9f5404056185427468634f18001d0fae2dc188d119232f15ad7d2d7b071de7e86e0a4b0a80e8394ce4eafa5b3c571821c7b42cfa1
@@ -64,7 +64,7 @@ module Switchman
64
64
  end
65
65
 
66
66
  # rebuild current shard activations - it might have "another" default shard serialized there
67
- active_shards.replace(active_shards.map do |category, shard|
67
+ active_shards.replace(active_shards.dup.map do |category, shard|
68
68
  shard = Shard.lookup((!shard || shard.default?) ? 'default' : shard.id)
69
69
  [category, shard]
70
70
  end.to_h)
@@ -88,7 +88,11 @@ module Switchman
88
88
  # Copypasta from Activerecord but with added global_id_for goodness.
89
89
  def records_for(ids)
90
90
  scope.where(association_key_name => ids).load do |record|
91
- global_key = Shard.global_id_for(record[association_key_name], record.shard)
91
+ global_key = if record.class.shard_category == :unsharded
92
+ convert_key(record[association_key_name])
93
+ else
94
+ Shard.global_id_for(record[association_key_name], record.shard)
95
+ end
92
96
  owner = owners_by_key[global_key.to_s].first
93
97
  association = owner.association(reflection.name)
94
98
  association.set_inverse_instance(record)
@@ -68,6 +68,14 @@ module Switchman
68
68
  result
69
69
  end
70
70
  end
71
+
72
+ def clear_query_caches_for_current_thread
73
+ ::ActiveRecord::Base.connection_handlers.each_value do |handler|
74
+ handler.connection_pool_list.each do |pool|
75
+ pool.connection(switch_shard: false).clear_query_cache if pool.active_connection?
76
+ end
77
+ end
78
+ end
71
79
  end
72
80
 
73
81
  def self.included(klass)
@@ -32,10 +32,10 @@ module Switchman
32
32
  conn
33
33
  end
34
34
 
35
- def connection
36
- conn = super
35
+ def connection(switch_shard: true)
36
+ conn = super()
37
37
  raise NonExistentShardError if shard.new_record?
38
- switch_database(conn) if conn.shard != self.shard
38
+ switch_database(conn) if conn.shard != self.shard && switch_shard
39
39
  conn
40
40
  end
41
41
 
@@ -53,10 +53,10 @@ module Switchman
53
53
  connection_pools.map(&:connections).inject([], &:+)
54
54
  end
55
55
 
56
- def connection
56
+ def connection(switch_shard: true)
57
57
  pool = current_pool
58
58
  begin
59
- connection = pool.connection
59
+ connection = pool.connection(switch_shard: switch_shard)
60
60
  connection.instance_variable_set(:@schema_cache, @schema_cache) unless ::Rails.version >= '6'
61
61
  connection
62
62
  rescue ConnectionError
@@ -3,6 +3,7 @@ require 'switchman/database_server'
3
3
  module Switchman
4
4
  class DefaultShard
5
5
  def id; 'default'; end
6
+ alias cache_key id
6
7
  def activate(*categories); yield; end
7
8
  def activate!(*categories); end
8
9
  def default?; true; end
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.14.7"
2
+ VERSION = "1.14.8"
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.14.7
4
+ version: 1.14.8
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-09-06 00:00:00.000000000 Z
13
+ date: 2019-11-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties