switchman 1.9.3 → 1.9.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
  SHA1:
3
- metadata.gz: dd6a78ff6974c70fd495154833ff83a7b1408d89
4
- data.tar.gz: a6ba5ec6032e7b82d808115cc09ce37d10a89b09
3
+ metadata.gz: 7953977b213e8fd57db12680f2e250db59e6cee0
4
+ data.tar.gz: 86a55be8ebd4c40c7071d0ef65886fd83102a4ce
5
5
  SHA512:
6
- metadata.gz: 9a3a696130257d94b959fd6ef57e200196fe9993aa066a356b6ebde4ef56076ac342bbd8bc866eb45e1e0c9cd3229201972b039a02f209b258ecc2788fabfa6a
7
- data.tar.gz: ce87fe2d582572246d05c7761b61fd3b4b1ce7dc49d90e0cf9037de78edfd73e67ba7641c87e6737320aca0b2ac30e8191d570f45ca82454ff045fc77dfc6158
6
+ metadata.gz: b1ccbcf0e7281cd022bf912a7cfc4dc43dc6801c3556e942929ca4bccd9c308feaed966dc84b3321238f263356bee6b23bfa9e177450555d9786405b48e2b04a
7
+ data.tar.gz: 73491652b599c6c693ffd60563aae72a63f84fef8d96c36aa7e3028edc7f0dc2099d30e328d6badc0088988b8a2b210319b8072e6874763cdb824f018e436d85
@@ -104,22 +104,18 @@ module Switchman
104
104
  end
105
105
  end
106
106
 
107
- def scope_class
108
- self.class.base_class
109
- end
110
-
111
107
  def save(*args)
112
108
  @shard_set_in_stone = true
113
- scope_class.shard(shard, :implicit).scoping { super }
109
+ self.class.shard(shard, :implicit).scoping { super }
114
110
  end
115
111
 
116
112
  def save!(*args)
117
113
  @shard_set_in_stone = true
118
- scope_class.shard(shard, :implicit).scoping { super }
114
+ self.class.shard(shard, :implicit).scoping { super }
119
115
  end
120
116
 
121
117
  def destroy
122
- scope_class.shard(shard, :implicit).scoping { super }
118
+ self.class.shard(shard, :implicit).scoping { super }
123
119
  end
124
120
 
125
121
  def clone
@@ -151,6 +147,14 @@ module Switchman
151
147
  @shard_set_in_stone = false
152
148
  copy
153
149
  end
150
+
151
+ if ::Rails.version >= '5'
152
+ def quoted_id
153
+ return super unless self.class.sharded_primary_key?
154
+ # do this the Rails 4.2 way, so that if Shard.current != self.shard, the id gets transposed
155
+ self.class.connection.quote(id, column_for_attribute(self.class.primary_key))
156
+ end
157
+ end
154
158
  end
155
159
  end
156
160
  end
@@ -1,79 +1,81 @@
1
1
  module Switchman
2
2
  module ActiveRecord
3
3
  module QueryCache
4
- # thread local accessors to replace @query_cache_enabled
5
- def query_cache
6
- thread_cache = Thread.current[:query_cache] ||= {}
7
- thread_cache[self.object_id] ||= Hash.new { |h,sql| h[sql] = {} }
8
- end
4
+ if ::Rails.version < '5.0.1'
5
+ # thread local accessors to replace @query_cache_enabled
6
+ def query_cache
7
+ thread_cache = Thread.current[:query_cache] ||= {}
8
+ thread_cache[self.object_id] ||= Hash.new { |h,sql| h[sql] = {} }
9
+ end
9
10
 
10
- def query_cache_enabled
11
- Thread.current[:query_cache_enabled]
12
- end
11
+ def query_cache_enabled
12
+ Thread.current[:query_cache_enabled]
13
+ end
13
14
 
14
- def query_cache_enabled=(value)
15
- Thread.current[:query_cache_enabled] = value
16
- end
15
+ def query_cache_enabled=(value)
16
+ Thread.current[:query_cache_enabled] = value
17
+ end
17
18
 
18
- # basically wholesale repeat of the methods from the original (see
19
- # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb),
20
- # but with self.query_cache_enabled and self.query_cache_enabled= instead
21
- # of @query_cache_enabled.
19
+ # basically wholesale repeat of the methods from the original (see
20
+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb),
21
+ # but with self.query_cache_enabled and self.query_cache_enabled= instead
22
+ # of @query_cache_enabled.
22
23
 
23
- def enable_query_cache!
24
- self.query_cache_enabled = true
25
- end
24
+ def enable_query_cache!
25
+ self.query_cache_enabled = true
26
+ end
26
27
 
27
- def disable_query_cache!
28
- self.query_cache_enabled = false
29
- end
28
+ def disable_query_cache!
29
+ self.query_cache_enabled = false
30
+ end
30
31
 
31
- def cache
32
- old, self.query_cache_enabled = query_cache_enabled, true
33
- yield
34
- ensure
35
- self.query_cache_enabled = old
36
- clear_query_cache unless self.query_cache_enabled
37
- end
32
+ def cache
33
+ old, self.query_cache_enabled = query_cache_enabled, true
34
+ yield
35
+ ensure
36
+ self.query_cache_enabled = old
37
+ clear_query_cache unless self.query_cache_enabled
38
+ end
38
39
 
39
- def uncached
40
- old, self.query_cache_enabled = query_cache_enabled, false
41
- yield
42
- ensure
43
- self.query_cache_enabled = old
44
- end
40
+ def uncached
41
+ old, self.query_cache_enabled = query_cache_enabled, false
42
+ yield
43
+ ensure
44
+ self.query_cache_enabled = old
45
+ end
45
46
 
46
- def clear_query_cache
47
- Thread.current[:query_cache]&.clear
48
- end
47
+ def clear_query_cache
48
+ Thread.current[:query_cache]&.clear
49
+ end
49
50
 
50
- def select_all(arel, name = nil, binds = [], preparable: nil)
51
- if self.query_cache_enabled && !locked?(arel)
52
- arel, binds = binds_from_relation(arel, binds)
53
- sql = to_sql(arel, binds)
54
- if ::Rails.version >= '5'
55
- cache_sql(sql, binds) { super(sql, name, binds, preparable: preparable) }
56
- else
57
- cache_sql(sql, binds) { super(sql, name, binds) }
58
- end
59
- else
60
- if ::Rails.version >= '5'
61
- super
51
+ def select_all(arel, name = nil, binds = [], preparable: nil)
52
+ if self.query_cache_enabled && !locked?(arel)
53
+ arel, binds = binds_from_relation(arel, binds)
54
+ sql = to_sql(arel, binds)
55
+ if ::Rails.version >= '5'
56
+ cache_sql(sql, binds) { super(sql, name, binds, preparable: preparable) }
57
+ else
58
+ cache_sql(sql, binds) { super(sql, name, binds) }
59
+ end
62
60
  else
63
- super(arel, name, binds)
61
+ if ::Rails.version >= '5'
62
+ super
63
+ else
64
+ super(arel, name, binds)
65
+ end
64
66
  end
65
67
  end
66
- end
67
68
 
68
- # no reason to define these on the including class directly. the super
69
- # works just as well from a method on the included module
70
- [:insert, :update, :delete].each do |method_name|
71
- class_eval <<-end_code, __FILE__, __LINE__ + 1
72
- def #{method_name}(*args)
73
- clear_query_cache if self.query_cache_enabled
74
- super
75
- end
76
- end_code
69
+ # no reason to define these on the including class directly. the super
70
+ # works just as well from a method on the included module
71
+ [:insert, :update, :delete].each do |method_name|
72
+ class_eval <<-end_code, __FILE__, __LINE__ + 1
73
+ def #{method_name}(*args)
74
+ clear_query_cache if self.query_cache_enabled
75
+ super
76
+ end
77
+ end_code
78
+ end
77
79
  end
78
80
 
79
81
  private
@@ -10,7 +10,7 @@ module Switchman
10
10
  end
11
11
 
12
12
  class ConnectionPoolProxy
13
- delegate :spec, :connected?, :default_schema, :with_connection,
13
+ delegate :spec, :connected?, :default_schema, :with_connection, :query_cache_enabled, :active_connection?,
14
14
  :to => :current_pool
15
15
 
16
16
  attr_reader :category, :schema_cache
@@ -71,7 +71,12 @@ module Switchman
71
71
  end
72
72
  end
73
73
 
74
- %w{release_connection disconnect! clear_reloadable_connections! verify_active_connections! clear_stale_cached_connections!}.each do |method|
74
+ %w{release_connection disconnect!
75
+ clear_reloadable_connections!
76
+ verify_active_connections!
77
+ clear_stale_cached_connections!
78
+ enable_query_cache!
79
+ disable_query_cache! }.each do |method|
75
80
  class_eval(<<-EOS)
76
81
  def #{method}
77
82
  @connection_pools.values.each(&:#{method})
@@ -126,6 +131,9 @@ module Switchman
126
131
 
127
132
  ::ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec).tap do |pool|
128
133
  pool.shard = shard
134
+ if ::Rails.version >= '5.0.1'
135
+ pool.enable_query_cache! if !@connection_pools.empty? && @connection_pools.first.last.query_cache_enabled
136
+ end
129
137
  end
130
138
  end
131
139
  end
@@ -124,7 +124,7 @@ module Switchman
124
124
  # we want it to find the definition from
125
125
  # ActiveRecord::ConnectionAdapters::DatabaseStatements, not
126
126
  # ActiveRecord::ConnectionAdapters::QueryCache
127
- ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all)
127
+ ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all) if ::Rails.version < '5.0.1'
128
128
 
129
129
  ::ActiveRecord::LogSubscriber.prepend(ActiveRecord::LogSubscriber)
130
130
  ::ActiveRecord::Reflection::AbstractReflection.include(ActiveRecord::Reflection::AbstractReflection)
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.9.3"
2
+ VERSION = "1.9.4"
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.9.3
4
+ version: 1.9.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: 2017-02-02 00:00:00.000000000 Z
13
+ date: 2017-03-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties