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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4910854dd97e92f0aab3a997b23c4f830d98e66f
4
- data.tar.gz: df78f89f7245ab25bd3ca40c06990ceb929b66f9
3
+ metadata.gz: b2e0335664e4c146e1d5270e519fd102eda815fa
4
+ data.tar.gz: 074003c3628875cf9e94cb8a8d1aa0f009baa9d1
5
5
  SHA512:
6
- metadata.gz: b25b5bd49ed22d0ca64d951b4384533711c0ee6451bd881fd6756786f97b3747ed10392756b1161460a0dc54f44a68c06847cb62f7e1387f568402405227411e
7
- data.tar.gz: e29b7d4237ed37008edc25450b75bc620c3f10f50855ce7403334098be94b91a127297969c9bd4d6415f3ba106d626d9252fe39fc9ce94452a4e774b9d6a3e5c
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
- if self == ActiveRecord::Base
28
- false
29
- elsif self == base_class
30
- on_slave_by_default
31
- else
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.10.0
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-04 00:00:00.000000000 Z
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: