active_record_shards 3.15.2 → 3.15.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6173b1dc57889f56b60dc15ad031d64ea6494a4c11c9bfcf63ba68215012137
|
4
|
+
data.tar.gz: efe84a0c10df29ef923e959aaf6c187d81dbd1f953ac30eda66457c8a344e0fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16dded6c3889b89e399f346fed1d9f779ce091a1abb7136e20c2e587c7fe6db6b58fcbdd8e6cce7969db2c1199a94420118964fa8715a65e0156b6a0dbf66e36
|
7
|
+
data.tar.gz: ade8122972a9bfb7cec49957101856ecaf685f4174cc2b7400ddcfb0131f0b16996d68e464752e2e45495abf56141478898e33a9c573a6e0b821fa0ea997000f
|
@@ -31,9 +31,9 @@ module ActiveRecordShards
|
|
31
31
|
switch_connection(old_options)
|
32
32
|
end
|
33
33
|
|
34
|
-
def on_first_shard
|
34
|
+
def on_first_shard(&block)
|
35
35
|
shard_name = shard_names.first
|
36
|
-
on_shard(shard_name)
|
36
|
+
on_shard(shard_name, &block)
|
37
37
|
end
|
38
38
|
|
39
39
|
def shards
|
@@ -170,9 +170,9 @@ module ActiveRecordShards
|
|
170
170
|
ActiveRecordShards.rails_env
|
171
171
|
end
|
172
172
|
|
173
|
-
def with_default_shard
|
173
|
+
def with_default_shard(&block)
|
174
174
|
if is_sharded? && current_shard_id.nil? && table_name != ActiveRecord::SchemaMigration.table_name
|
175
|
-
on_first_shard
|
175
|
+
on_first_shard(&block)
|
176
176
|
else
|
177
177
|
yield
|
178
178
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module ActiveRecordShards
|
3
3
|
module DefaultSlavePatches
|
4
|
-
def self.wrap_method_in_on_slave(class_method, base, method)
|
4
|
+
def self.wrap_method_in_on_slave(class_method, base, method, force_on_slave: false)
|
5
5
|
base_methods =
|
6
6
|
if class_method
|
7
7
|
base.methods + base.private_methods
|
@@ -11,10 +11,12 @@ module ActiveRecordShards
|
|
11
11
|
|
12
12
|
return unless base_methods.include?(method)
|
13
13
|
_, method, punctuation = method.to_s.match(/^(.*?)([\?\!]?)$/).to_a
|
14
|
+
# _ALWAYS_ on slave, or only for on `on_slave_by_default = true` models?
|
15
|
+
wrapper = force_on_slave ? 'force_on_slave' : 'on_slave_unless_tx'
|
14
16
|
base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
15
17
|
#{class_method ? 'class << self' : ''}
|
16
18
|
def #{method}_with_default_slave#{punctuation}(*args, &block)
|
17
|
-
|
19
|
+
#{wrapper} do
|
18
20
|
#{method}_without_default_slave#{punctuation}(*args, &block)
|
19
21
|
end
|
20
22
|
end
|
@@ -25,18 +27,6 @@ module ActiveRecordShards
|
|
25
27
|
RUBY
|
26
28
|
end
|
27
29
|
|
28
|
-
def columns_with_force_slave(*args, &block)
|
29
|
-
on_cx_switch_block(:slave, construct_ro_scope: false, force: true) do
|
30
|
-
columns_without_force_slave(*args, &block)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def table_exists_with_force_slave?(*args, &block)
|
35
|
-
on_cx_switch_block(:slave, construct_ro_scope: false, force: true) do
|
36
|
-
table_exists_without_force_slave?(*args, &block)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
30
|
def transaction_with_slave_off(*args, &block)
|
41
31
|
if on_slave_by_default?
|
42
32
|
begin
|
@@ -58,21 +48,33 @@ module ActiveRecordShards
|
|
58
48
|
end
|
59
49
|
end
|
60
50
|
|
61
|
-
CLASS_SLAVE_METHODS = [
|
51
|
+
CLASS_SLAVE_METHODS = [
|
52
|
+
:calculate,
|
53
|
+
:count_by_sql,
|
54
|
+
:exists?,
|
55
|
+
:find_by_sql,
|
56
|
+
:find_every,
|
57
|
+
:find_one,
|
58
|
+
:find_some
|
59
|
+
].freeze
|
60
|
+
|
61
|
+
CLASS_FORCE_SLAVE_METHODS = [
|
62
|
+
:columns,
|
63
|
+
:replace_bind_variable,
|
64
|
+
:replace_bind_variables,
|
65
|
+
:sanitize_sql_array,
|
66
|
+
:sanitize_sql_hash_for_assignment,
|
67
|
+
:table_exists?
|
68
|
+
].freeze
|
62
69
|
|
63
70
|
def self.extended(base)
|
64
71
|
CLASS_SLAVE_METHODS.each { |m| ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(true, base, m) }
|
72
|
+
CLASS_FORCE_SLAVE_METHODS.each { |m| ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(true, base, m, force_on_slave: true) }
|
65
73
|
|
66
74
|
base.class_eval do
|
67
75
|
include InstanceMethods
|
68
76
|
|
69
77
|
class << self
|
70
|
-
alias_method :columns_without_force_slave, :columns
|
71
|
-
alias_method :columns, :columns_with_force_slave
|
72
|
-
|
73
|
-
alias_method :table_exists_without_force_slave?, :table_exists?
|
74
|
-
alias_method :table_exists?, :table_exists_with_force_slave?
|
75
|
-
|
76
78
|
alias_method :transaction_without_slave_off, :transaction
|
77
79
|
alias_method :transaction, :transaction_with_slave_off
|
78
80
|
end
|
@@ -83,14 +85,18 @@ module ActiveRecordShards
|
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
|
-
def on_slave_unless_tx
|
88
|
+
def on_slave_unless_tx(&block)
|
87
89
|
if on_slave_by_default? && !Thread.current[:_active_record_shards_slave_off]
|
88
|
-
on_slave
|
90
|
+
on_slave(&block)
|
89
91
|
else
|
90
92
|
yield
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
96
|
+
def force_on_slave(&block)
|
97
|
+
on_cx_switch_block(:slave, construct_ro_scope: false, force: true, &block)
|
98
|
+
end
|
99
|
+
|
94
100
|
module ActiveRelationPatches
|
95
101
|
def self.included(base)
|
96
102
|
[:calculate, :exists?, :pluck, :load].each do |m|
|
@@ -99,12 +105,14 @@ module ActiveRecordShards
|
|
99
105
|
|
100
106
|
if ActiveRecord::VERSION::MAJOR == 4
|
101
107
|
# `where` and `having` clauses call `create_binds`, which will use the master connection
|
102
|
-
ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(false, base, :create_binds)
|
108
|
+
ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(false, base, :create_binds, force_on_slave: true)
|
103
109
|
end
|
110
|
+
|
111
|
+
ActiveRecordShards::DefaultSlavePatches.wrap_method_in_on_slave(false, base, :to_sql, force_on_slave: true)
|
104
112
|
end
|
105
113
|
|
106
|
-
def on_slave_unless_tx
|
107
|
-
@klass.on_slave_unless_tx
|
114
|
+
def on_slave_unless_tx(&block)
|
115
|
+
@klass.on_slave_unless_tx(&block)
|
108
116
|
end
|
109
117
|
end
|
110
118
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_shards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.15.
|
4
|
+
version: 3.15.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Quorning
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2019-
|
16
|
+
date: 2019-11-05 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activerecord
|