distribute_reads 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +6 -6
- data/lib/distribute_reads/version.rb +1 -1
- data/lib/distribute_reads.rb +4 -5
- metadata +20 -7
- data/lib/distribute_reads/cache_store.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 498115398e131f837029f3ad86c21ea646204b399f732a800b32687135bee154
|
4
|
+
data.tar.gz: 40c983fa023cab9fe00b5f0e7b03925d2f1d7c6e3d30056a26e9c147fd92d4b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a3a60620721ef9b23d1faf8a742386dfd58d3830ee7b110dbc44d100d7fd7670189e8893f1d21eab4d7bced008942f8fe8116756ae1aae6cec0f9427b3018d4
|
7
|
+
data.tar.gz: 56b65735bffb296bcfc8719c847988c0ecc4610c21ecad650115181431ac85b0b7cd686c7a409cede3cfc25c9a54de74e6f053556ea9ca6c28feb242e6ad1709
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Scale database reads to replicas in Rails
|
|
4
4
|
|
5
5
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
|
6
6
|
|
7
|
-
[![Build Status](https://github.com/ankane/distribute_reads/workflows/build/badge.svg
|
7
|
+
[![Build Status](https://github.com/ankane/distribute_reads/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/distribute_reads/actions)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -74,7 +74,7 @@ You can pass any options as well.
|
|
74
74
|
|
75
75
|
## Lazy Evaluation
|
76
76
|
|
77
|
-
|
77
|
+
Active Record uses [lazy evaluation](https://www.theodinproject.com/courses/ruby-on-rails/lessons/active-record-queries), which can delay the execution of a query to outside of a `distribute_reads` block. In this case, the primary will be used.
|
78
78
|
|
79
79
|
```ruby
|
80
80
|
users = distribute_reads { User.where(orders_count: 1) } # not executed yet
|
@@ -185,9 +185,9 @@ distribute_reads(replica: true) do
|
|
185
185
|
end
|
186
186
|
```
|
187
187
|
|
188
|
-
## Rails
|
188
|
+
## Rails
|
189
189
|
|
190
|
-
Rails 6 has [native support for replicas](https://guides.rubyonrails.org/active_record_multiple_databases.html) :tada:
|
190
|
+
Rails 6+ has [native support for replicas](https://guides.rubyonrails.org/active_record_multiple_databases.html) :tada:
|
191
191
|
|
192
192
|
```ruby
|
193
193
|
ActiveRecord::Base.connected_to(role: :reading) do
|
@@ -195,11 +195,11 @@ ActiveRecord::Base.connected_to(role: :reading) do
|
|
195
195
|
end
|
196
196
|
```
|
197
197
|
|
198
|
-
However, it’s not able to
|
198
|
+
However, it’s not able to do automatic statement-based routing like Makara yet.
|
199
199
|
|
200
200
|
## Thanks
|
201
201
|
|
202
|
-
Thanks to [TaskRabbit](https://github.com/taskrabbit) for Makara, [Sherin Kurian](https://github.com/
|
202
|
+
Thanks to [TaskRabbit](https://github.com/taskrabbit) for Makara, [Sherin Kurian](https://github.com/sherin) for the max lag option, and [Nick Elser](https://github.com/nickelser) for the write-through cache.
|
203
203
|
|
204
204
|
## History
|
205
205
|
|
data/lib/distribute_reads.rb
CHANGED
@@ -3,10 +3,9 @@ require "active_support"
|
|
3
3
|
require "makara"
|
4
4
|
|
5
5
|
# modules
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
require "distribute_reads/version"
|
6
|
+
require_relative "distribute_reads/appropriate_pool"
|
7
|
+
require_relative "distribute_reads/global_methods"
|
8
|
+
require_relative "distribute_reads/version"
|
10
9
|
|
11
10
|
module DistributeReads
|
12
11
|
class Error < StandardError; end
|
@@ -164,6 +163,6 @@ Object.include DistributeReads::GlobalMethods
|
|
164
163
|
Object.send :private, :distribute_reads
|
165
164
|
|
166
165
|
ActiveSupport.on_load(:active_job) do
|
167
|
-
|
166
|
+
require_relative "distribute_reads/job_methods"
|
168
167
|
include DistributeReads::JobMethods
|
169
168
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distribute_reads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: makara
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
33
|
+
version: '0.5'
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
40
|
+
version: '0.5'
|
27
41
|
description:
|
28
42
|
email: andrew@ankane.org
|
29
43
|
executables: []
|
@@ -35,7 +49,6 @@ files:
|
|
35
49
|
- README.md
|
36
50
|
- lib/distribute_reads.rb
|
37
51
|
- lib/distribute_reads/appropriate_pool.rb
|
38
|
-
- lib/distribute_reads/cache_store.rb
|
39
52
|
- lib/distribute_reads/global_methods.rb
|
40
53
|
- lib/distribute_reads/job_methods.rb
|
41
54
|
- lib/distribute_reads/version.rb
|
@@ -51,14 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
64
|
requirements:
|
52
65
|
- - ">="
|
53
66
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
67
|
+
version: '3.1'
|
55
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
69
|
requirements:
|
57
70
|
- - ">="
|
58
71
|
- !ruby/object:Gem::Version
|
59
72
|
version: '0'
|
60
73
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.5.11
|
62
75
|
signing_key:
|
63
76
|
specification_version: 4
|
64
77
|
summary: Scale database reads with replicas in Rails
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module DistributeReads
|
2
|
-
class CacheStore
|
3
|
-
def read(key)
|
4
|
-
memory_cached = memory_store.read(key)
|
5
|
-
return nil if memory_cached == :nil
|
6
|
-
return memory_cached if memory_cached
|
7
|
-
|
8
|
-
store_cached = store.try(:read, key)
|
9
|
-
memory_store.write(key, store_cached || :nil)
|
10
|
-
store_cached
|
11
|
-
end
|
12
|
-
|
13
|
-
def write(*args)
|
14
|
-
memory_store.write(*args)
|
15
|
-
store.try(:write, *args)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
# use ActiveSupport::Cache::MemoryStore instead?
|
21
|
-
def memory_store
|
22
|
-
@memory_store ||= Makara::Cache::MemoryStore.new
|
23
|
-
end
|
24
|
-
|
25
|
-
def store
|
26
|
-
@store ||= Rails.cache
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|