activerecord-turntable 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ ## activerecord-turntable 1.1.0 ##
2
+
3
+ * AR::Base.clear_active_connections! should be proxied to all shards
4
+
5
+ * Reduce unnecessary query when reloading
6
+
7
+
8
+ ## activerecord-turntable 1.0.1 ##
9
+
10
+ * Added missing setting for sequences at README and turntable.yml template.
11
+
12
+
13
+ ## activerecord-turntable 1.0.0 ##
14
+
15
+ * First Release!
data/README.rdoc CHANGED
@@ -12,7 +12,7 @@ Currently supports mysql only.
12
12
 
13
13
  Add 'activerecord-turntable' to Gemfile:
14
14
 
15
- gem 'activerecord-turntable', '1.0.0'
15
+ gem 'activerecord-turntable', '1.0.1'
16
16
 
17
17
  Run a bundle install:
18
18
 
@@ -12,7 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.rubyforge_project = "activerecord-turntable"
13
13
  s.extra_rdoc_files = [
14
14
  "LICENSE.txt",
15
- "README.rdoc"
15
+ "README.rdoc",
16
+ "CHANGELOG.md"
16
17
  ]
17
18
 
18
19
  s.files = `git ls-files | grep -v "^spec"`.split("\n")
@@ -1,5 +1,27 @@
1
1
  module ActiveRecord::Turntable::ActiveRecordExt
2
2
  module Persistence
3
+ ::ActiveRecord::Persistence.class_eval do
4
+ def reload(options = nil)
5
+ clear_aggregation_cache
6
+ clear_association_cache
7
+
8
+ ::ActiveRecord::IdentityMap.without do
9
+ fresh_object = self.class.unscoped {
10
+ finder_scope = if turntable_enabled? and self.class.primary_key != self.class.turntable_shard_key.to_s
11
+ self.class.where(self.class.turntable_shard_key => self.send(turntable_shard_key))
12
+ else
13
+ self.class
14
+ end
15
+ finder_scope.find(self.id, options)
16
+ }
17
+ @attributes.update(fresh_object.instance_variable_get('@attributes'))
18
+ end
19
+
20
+ @attributes_cache = {}
21
+ self
22
+ end
23
+ end
24
+
3
25
  if ActiveRecord::VERSION::STRING < '3.1'
4
26
  ::ActiveRecord::Persistence.class_eval do
5
27
  def destroy
@@ -77,7 +77,7 @@ module ActiveRecord::Turntable
77
77
  raise "Please install the #{config['adapter']} adapter: `gem install activerecord-#{config['adapter']}-adapter` (#{e})"
78
78
  end
79
79
  adapter_method = "#{config['adapter']}_connection"
80
- ActiveRecord::Base::ConnectionSpecification.new(config.symbolize_keys, adapter_method)
80
+ ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method)
81
81
  end
82
82
 
83
83
  def clear_all_connections!
@@ -45,8 +45,10 @@ module ActiveRecord::Turntable
45
45
  end
46
46
  end
47
47
 
48
- %w(disconnect! release_connection clear_all_connections! clear_reloadable_connections! clear_stale_cached_connections! verify_active_connections!).each do |name|
48
+ %w(disconnect! release_connection clear_all_connections! clear_active_connections! clear_reloadable_connections! clear_stale_cached_connections! verify_active_connections!).each do |name|
49
49
  define_method(name.to_sym) do
50
+ @proxy.master.connection_pool.send(name.to_sym)
51
+ @proxy.seq.connection_pool.try(name.to_sym) if @proxy.respond_to?(:seq)
50
52
  @proxy.shards.values.each do |pool|
51
53
  pool.connection_pool.send(name.to_sym)
52
54
  end
@@ -41,7 +41,7 @@ module ActiveRecord::Turntable
41
41
  raise "Please install the #{config['adapter']} adapter: `gem install activerecord-#{config['adapter']}-adapter` (#{e})"
42
42
  end
43
43
  adapter_method = "#{config['adapter']}_connection"
44
- ActiveRecord::Base::ConnectionSpecification.new(config.symbolize_keys, adapter_method)
44
+ ActiveRecord::Base::ConnectionSpecification.new(config, adapter_method)
45
45
  end
46
46
  end
47
47
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Turntable
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -112,13 +112,25 @@ describe ActiveRecord::Turntable::ActiveRecordExt::Persistence do
112
112
  expect {
113
113
  user_status.destroy
114
114
  }.to_not raise_error
115
- puts strio.string
116
115
  strio.string.should =~ /WHERE `user_statuses`\.`id` = #{user_status.id} AND `user_statuses`\.`user_id` = #{user_status.user_id}[^\s]*$/
117
116
  end
118
117
 
119
118
  it "should warn when creating without shard_key" do
120
119
  pending "doesn't need to implemented soon"
121
120
  end
121
+
122
+ it "should execute one query when reloading" do
123
+ user; user_status
124
+ strio = StringIO.new
125
+ ActiveRecord::Base.logger = Logger.new(strio)
126
+
127
+ expect {
128
+ user_status.reload
129
+ }.to_not raise_error
130
+ puts strio.string
131
+
132
+ strio.string.split("\n").select {|stmt| stmt =~ /SELECT/}.should have(1).items
133
+ end
122
134
  end
123
135
 
124
136
  context "When the model is not sharded" do
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-turntable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
4
  prerelease:
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - gussan
@@ -12,245 +12,245 @@ cert_chain: []
12
12
  date: 2013-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: activerecord
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
15
+ version_requirements: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
20
+ none: false
21
+ name: activerecord
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
24
+ requirement: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ! '>='
28
27
  - !ruby/object:Gem::Version
29
28
  version: 3.0.0
30
- - !ruby/object:Gem::Dependency
31
- name: activesupport
32
- requirement: !ruby/object:Gem::Requirement
33
29
  none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
34
32
  requirements:
35
33
  - - ! '>='
36
34
  - !ruby/object:Gem::Version
37
35
  version: 3.0.0
36
+ none: false
37
+ name: activesupport
38
38
  type: :runtime
39
39
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
40
+ requirement: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ! '>='
44
43
  - !ruby/object:Gem::Version
45
44
  version: 3.0.0
46
- - !ruby/object:Gem::Dependency
47
- name: sql_tree
48
- requirement: !ruby/object:Gem::Requirement
49
45
  none: false
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
50
48
  requirements:
51
49
  - - '='
52
50
  - !ruby/object:Gem::Version
53
51
  version: 0.2.0
52
+ none: false
53
+ name: sql_tree
54
54
  type: :runtime
55
55
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
56
+ requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - '='
60
59
  - !ruby/object:Gem::Version
61
60
  version: 0.2.0
62
- - !ruby/object:Gem::Dependency
63
- name: bsearch
64
- requirement: !ruby/object:Gem::Requirement
65
61
  none: false
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: !ruby/object:Gem::Requirement
66
64
  requirements:
67
65
  - - ~>
68
66
  - !ruby/object:Gem::Version
69
67
  version: '1.5'
68
+ none: false
69
+ name: bsearch
70
70
  type: :runtime
71
71
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
72
+ requirement: !ruby/object:Gem::Requirement
74
73
  requirements:
75
74
  - - ~>
76
75
  - !ruby/object:Gem::Version
77
76
  version: '1.5'
78
- - !ruby/object:Gem::Dependency
79
- name: httpclient
80
- requirement: !ruby/object:Gem::Requirement
81
77
  none: false
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: !ruby/object:Gem::Requirement
82
80
  requirements:
83
81
  - - ! '>='
84
82
  - !ruby/object:Gem::Version
85
83
  version: '0'
84
+ none: false
85
+ name: httpclient
86
86
  type: :runtime
87
87
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
88
+ requirement: !ruby/object:Gem::Requirement
90
89
  requirements:
91
90
  - - ! '>='
92
91
  - !ruby/object:Gem::Version
93
92
  version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: rake
96
- requirement: !ruby/object:Gem::Requirement
97
93
  none: false
94
+ - !ruby/object:Gem::Dependency
95
+ version_requirements: !ruby/object:Gem::Requirement
98
96
  requirements:
99
97
  - - ~>
100
98
  - !ruby/object:Gem::Version
101
99
  version: 0.9.2
100
+ none: false
101
+ name: rake
102
102
  type: :development
103
103
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
104
+ requirement: !ruby/object:Gem::Requirement
106
105
  requirements:
107
106
  - - ~>
108
107
  - !ruby/object:Gem::Version
109
108
  version: 0.9.2
110
- - !ruby/object:Gem::Dependency
111
- name: rspec
112
- requirement: !ruby/object:Gem::Requirement
113
109
  none: false
110
+ - !ruby/object:Gem::Dependency
111
+ version_requirements: !ruby/object:Gem::Requirement
114
112
  requirements:
115
113
  - - ! '>='
116
114
  - !ruby/object:Gem::Version
117
115
  version: '0'
116
+ none: false
117
+ name: rspec
118
118
  type: :development
119
119
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
120
+ requirement: !ruby/object:Gem::Requirement
122
121
  requirements:
123
122
  - - ! '>='
124
123
  - !ruby/object:Gem::Version
125
124
  version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: rr
128
- requirement: !ruby/object:Gem::Requirement
129
125
  none: false
126
+ - !ruby/object:Gem::Dependency
127
+ version_requirements: !ruby/object:Gem::Requirement
130
128
  requirements:
131
129
  - - ! '>='
132
130
  - !ruby/object:Gem::Version
133
131
  version: '0'
132
+ none: false
133
+ name: rr
134
134
  type: :development
135
135
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
136
+ requirement: !ruby/object:Gem::Requirement
138
137
  requirements:
139
138
  - - ! '>='
140
139
  - !ruby/object:Gem::Version
141
140
  version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: mysql2
144
- requirement: !ruby/object:Gem::Requirement
145
141
  none: false
142
+ - !ruby/object:Gem::Dependency
143
+ version_requirements: !ruby/object:Gem::Requirement
146
144
  requirements:
147
145
  - - ! '>='
148
146
  - !ruby/object:Gem::Version
149
147
  version: '0'
148
+ none: false
149
+ name: mysql2
150
150
  type: :development
151
151
  prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
152
+ requirement: !ruby/object:Gem::Requirement
154
153
  requirements:
155
154
  - - ! '>='
156
155
  - !ruby/object:Gem::Version
157
156
  version: '0'
158
- - !ruby/object:Gem::Dependency
159
- name: fabrication
160
- requirement: !ruby/object:Gem::Requirement
161
157
  none: false
158
+ - !ruby/object:Gem::Dependency
159
+ version_requirements: !ruby/object:Gem::Requirement
162
160
  requirements:
163
161
  - - ! '>='
164
162
  - !ruby/object:Gem::Version
165
163
  version: '0'
164
+ none: false
165
+ name: fabrication
166
166
  type: :development
167
167
  prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
168
+ requirement: !ruby/object:Gem::Requirement
170
169
  requirements:
171
170
  - - ! '>='
172
171
  - !ruby/object:Gem::Version
173
172
  version: '0'
174
- - !ruby/object:Gem::Dependency
175
- name: faker
176
- requirement: !ruby/object:Gem::Requirement
177
173
  none: false
174
+ - !ruby/object:Gem::Dependency
175
+ version_requirements: !ruby/object:Gem::Requirement
178
176
  requirements:
179
177
  - - ! '>='
180
178
  - !ruby/object:Gem::Version
181
179
  version: '0'
180
+ none: false
181
+ name: faker
182
182
  type: :development
183
183
  prerelease: false
184
- version_requirements: !ruby/object:Gem::Requirement
185
- none: false
184
+ requirement: !ruby/object:Gem::Requirement
186
185
  requirements:
187
186
  - - ! '>='
188
187
  - !ruby/object:Gem::Version
189
188
  version: '0'
190
- - !ruby/object:Gem::Dependency
191
- name: activerecord-import
192
- requirement: !ruby/object:Gem::Requirement
193
189
  none: false
190
+ - !ruby/object:Gem::Dependency
191
+ version_requirements: !ruby/object:Gem::Requirement
194
192
  requirements:
195
193
  - - ! '>='
196
194
  - !ruby/object:Gem::Version
197
195
  version: '0'
196
+ none: false
197
+ name: activerecord-import
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: !ruby/object:Gem::Requirement
201
- none: false
200
+ requirement: !ruby/object:Gem::Requirement
202
201
  requirements:
203
202
  - - ! '>='
204
203
  - !ruby/object:Gem::Version
205
204
  version: '0'
206
- - !ruby/object:Gem::Dependency
207
- name: pry
208
- requirement: !ruby/object:Gem::Requirement
209
205
  none: false
206
+ - !ruby/object:Gem::Dependency
207
+ version_requirements: !ruby/object:Gem::Requirement
210
208
  requirements:
211
209
  - - ! '>='
212
210
  - !ruby/object:Gem::Version
213
211
  version: '0'
212
+ none: false
213
+ name: pry
214
214
  type: :development
215
215
  prerelease: false
216
- version_requirements: !ruby/object:Gem::Requirement
217
- none: false
216
+ requirement: !ruby/object:Gem::Requirement
218
217
  requirements:
219
218
  - - ! '>='
220
219
  - !ruby/object:Gem::Version
221
220
  version: '0'
222
- - !ruby/object:Gem::Dependency
223
- name: guard-rspec
224
- requirement: !ruby/object:Gem::Requirement
225
221
  none: false
222
+ - !ruby/object:Gem::Dependency
223
+ version_requirements: !ruby/object:Gem::Requirement
226
224
  requirements:
227
225
  - - ! '>='
228
226
  - !ruby/object:Gem::Version
229
227
  version: '0'
228
+ none: false
229
+ name: guard-rspec
230
230
  type: :development
231
231
  prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- none: false
232
+ requirement: !ruby/object:Gem::Requirement
234
233
  requirements:
235
234
  - - ! '>='
236
235
  - !ruby/object:Gem::Version
237
236
  version: '0'
238
- - !ruby/object:Gem::Dependency
239
- name: growl
240
- requirement: !ruby/object:Gem::Requirement
241
237
  none: false
238
+ - !ruby/object:Gem::Dependency
239
+ version_requirements: !ruby/object:Gem::Requirement
242
240
  requirements:
243
241
  - - ! '>='
244
242
  - !ruby/object:Gem::Version
245
243
  version: '0'
244
+ none: false
245
+ name: growl
246
246
  type: :development
247
247
  prerelease: false
248
- version_requirements: !ruby/object:Gem::Requirement
249
- none: false
248
+ requirement: !ruby/object:Gem::Requirement
250
249
  requirements:
251
250
  - - ! '>='
252
251
  - !ruby/object:Gem::Version
253
252
  version: '0'
253
+ none: false
254
254
  description: AcviveRecord Sharding plugin
255
255
  email:
256
256
  executables: []
@@ -258,11 +258,13 @@ extensions: []
258
258
  extra_rdoc_files:
259
259
  - LICENSE.txt
260
260
  - README.rdoc
261
+ - CHANGELOG.md
261
262
  files:
262
263
  - .document
263
264
  - .gitignore
264
265
  - .rspec
265
266
  - .travis.yml
267
+ - CHANGELOG.md
266
268
  - Gemfile
267
269
  - Guardfile
268
270
  - LICENSE.txt
@@ -400,17 +402,17 @@ rdoc_options: []
400
402
  require_paths:
401
403
  - lib
402
404
  required_ruby_version: !ruby/object:Gem::Requirement
403
- none: false
404
405
  requirements:
405
406
  - - ! '>='
406
407
  - !ruby/object:Gem::Version
407
408
  version: '0'
408
- required_rubygems_version: !ruby/object:Gem::Requirement
409
409
  none: false
410
+ required_rubygems_version: !ruby/object:Gem::Requirement
410
411
  requirements:
411
412
  - - ! '>='
412
413
  - !ruby/object:Gem::Version
413
414
  version: '0'
415
+ none: false
414
416
  requirements: []
415
417
  rubyforge_project: activerecord-turntable
416
418
  rubygems_version: 1.8.23