active_record_shards 3.10.0 → 3.11.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 +4 -4
- data/README.md +9 -0
- data/lib/active_record_shards/model.rb +5 -10
- data/lib/active_record_shards/sql_comments.rb +16 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2e0335664e4c146e1d5270e519fd102eda815fa
|
4
|
+
data.tar.gz: 074003c3628875cf9e94cb8a8d1aa0f009baa9d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4caa2e0aeea79f006eef29d1dd6b5c80908c68f72de26c3383ed13cc85682586a5d62cd3bad0460bf969b4d8f26fadc7167f730a468bfd1c8d12bfcbeb776497
|
7
|
+
data.tar.gz: 5fa6b720056fab9c81c95c49e5e0ad474d85cae217910e68b1e3f5040082c6c5dd693bfd40524e6476fee75a7008847308d8940493c5422b4fd0848b26388c23
|
data/README.md
CHANGED
@@ -91,6 +91,15 @@ This will perform the query on the slave, and mark the returned instances as rea
|
|
91
91
|
|
92
92
|
Account.on_slave.find_by_big_expensive_query
|
93
93
|
|
94
|
+
## Debugging
|
95
|
+
|
96
|
+
Show if a query went to master or slave in the logs:
|
97
|
+
|
98
|
+
```Ruby
|
99
|
+
require 'active_record_shards/sql_comments'
|
100
|
+
ActiveRecordShards::SqlComments.enable
|
101
|
+
```
|
102
|
+
|
94
103
|
## Copyright
|
95
104
|
|
96
105
|
Copyright (c) 2011 Zendesk. See LICENSE for details.
|
@@ -24,13 +24,11 @@ module ActiveRecordShards
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def on_slave_by_default?
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
base_class.on_slave_by_default?
|
33
|
-
end
|
27
|
+
base_class.instance_variable_get(:@on_slave_by_default)
|
28
|
+
end
|
29
|
+
|
30
|
+
def on_slave_by_default=(value)
|
31
|
+
base_class.instance_variable_set(:@on_slave_by_default, value)
|
34
32
|
end
|
35
33
|
|
36
34
|
module InstanceMethods
|
@@ -53,11 +51,8 @@ module ActiveRecordShards
|
|
53
51
|
base.after_initialize :initialize_shard_and_slave
|
54
52
|
end
|
55
53
|
|
56
|
-
attr_writer :on_slave_by_default
|
57
|
-
|
58
54
|
private
|
59
55
|
|
60
|
-
attr_reader :on_slave_by_default
|
61
56
|
attr_accessor :sharded
|
62
57
|
end
|
63
58
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# show which connection was picked to debug master/slave slowness when both servers are the same
|
2
|
+
module ActiveRecordShards
|
3
|
+
module SqlComments
|
4
|
+
module Methods
|
5
|
+
def execute(query, name = nil)
|
6
|
+
slave = ActiveRecord::Base.current_shard_selection.on_slave?
|
7
|
+
query += " /* #{slave ? 'slave' : 'master'} */"
|
8
|
+
super(query, name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.enable
|
13
|
+
ActiveRecord::Base.connection.class.prepend(Methods)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
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.
|
4
|
+
version: 3.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mick Staugaard
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-09-
|
13
|
+
date: 2017-09-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/active_record_shards/schema_dumper_extension.rb
|
208
208
|
- lib/active_record_shards/shard_selection.rb
|
209
209
|
- lib/active_record_shards/shard_support.rb
|
210
|
+
- lib/active_record_shards/sql_comments.rb
|
210
211
|
- lib/active_record_shards/tasks.rb
|
211
212
|
homepage: https://github.com/zendesk/active_record_shards
|
212
213
|
licenses:
|