couch_potato 1.16.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/lib/couch_potato/database.rb +3 -2
- data/lib/couch_potato/version.rb +1 -1
- data/spec/unit/caching_spec.rb +20 -16
- data/spec/unit/database_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a78d19f65a75932bb6f60639fc9ad3dff0151e9c7de7f8cbc31e1b61038f7fa8
|
4
|
+
data.tar.gz: c5383ffd3db50bd45d727a84b62588dcd70d6ea3d07ac96559e1318c145fb057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38aa7ce10b0f12429789ecc0f25e34b276f98eadedac900f2ea18b7c1845549be28becb624d4da1c89506d814fa403b7f9647f960f3be534ac47b02c839f6866
|
7
|
+
data.tar.gz: e0b48a96f9a485d0765b066b5e5bca043058b85af246775abdf2bf3afb598bf691b09ae156182b9ecf1ff9dcc0acdee3bb5cc899a8722d0a75bdff9ded965b7b
|
data/CHANGES.md
CHANGED
@@ -149,7 +149,7 @@ module CouchPotato
|
|
149
149
|
|
150
150
|
cached = cache && cache[id]
|
151
151
|
if cache
|
152
|
-
if
|
152
|
+
if cache.key?(id)
|
153
153
|
ActiveSupport::Notifications.instrument('couch_potato.load.cached', id: id, doc: cached) do
|
154
154
|
cached
|
155
155
|
end
|
@@ -164,6 +164,7 @@ module CouchPotato
|
|
164
164
|
alias load load_document
|
165
165
|
|
166
166
|
def load_documents(ids)
|
167
|
+
ids = ids.compact
|
167
168
|
return [] if ids.empty?
|
168
169
|
|
169
170
|
uncached_ids = ids - (cache&.keys || [])
|
@@ -177,7 +178,7 @@ module CouchPotato
|
|
177
178
|
if cache
|
178
179
|
uncached_ids.each do |id|
|
179
180
|
doc = uncached_docs_by_id[id]
|
180
|
-
cache[id] = doc
|
181
|
+
cache[id] = doc
|
181
182
|
end
|
182
183
|
end
|
183
184
|
ids.filter_map { |id| (cached_docs_by_id[id]) || uncached_docs_by_id[id] }
|
data/lib/couch_potato/version.rb
CHANGED
data/spec/unit/caching_spec.rb
CHANGED
@@ -37,6 +37,15 @@ RSpec.describe 'database caching' do
|
|
37
37
|
db.load '1'
|
38
38
|
end
|
39
39
|
|
40
|
+
it 'caches nil' do
|
41
|
+
allow(couchrest_db).to receive(:get).with('1').and_return(nil)
|
42
|
+
|
43
|
+
db.load '1'
|
44
|
+
db.load '1'
|
45
|
+
|
46
|
+
expect(couchrest_db).to have_received(:get).with('1').exactly(1).times
|
47
|
+
end
|
48
|
+
|
40
49
|
it 'gets an object from the cache the 2nd time via #load!' do
|
41
50
|
expect(couchrest_db).to receive(:get).with('1').exactly(1).times
|
42
51
|
|
@@ -92,6 +101,17 @@ RSpec.describe 'database caching' do
|
|
92
101
|
expect(couchrest_db).to have_received(:bulk_load).with(['2']).exactly(1).times
|
93
102
|
end
|
94
103
|
|
104
|
+
it 'caches nil' do
|
105
|
+
allow(couchrest_db).to receive(:bulk_load).with(['1']).and_return('rows' => [{'doc' => nil}])
|
106
|
+
allow(couchrest_db).to receive(:bulk_load).with(['2']).and_return('rows' => [{'doc' => doc2}])
|
107
|
+
|
108
|
+
|
109
|
+
db.load_document(['1'])
|
110
|
+
db.load_document(['1', '2'])
|
111
|
+
|
112
|
+
expect(couchrest_db).to have_received(:bulk_load).with(['1']).exactly(1).times
|
113
|
+
end
|
114
|
+
|
95
115
|
it 'instruments the load call' do
|
96
116
|
allow(couchrest_db).to receive(:bulk_load).with(['1'])
|
97
117
|
.and_return('rows' => [{'doc' => doc1}])
|
@@ -137,22 +157,6 @@ RSpec.describe 'database caching' do
|
|
137
157
|
|
138
158
|
expect(result).to eql([doc1, doc2])
|
139
159
|
end
|
140
|
-
|
141
|
-
it 'does not cache documents that do not respond to id' do
|
142
|
-
doc1 = {
|
143
|
-
'id' => '1',
|
144
|
-
}
|
145
|
-
doc2 = {
|
146
|
-
'id' => '2',
|
147
|
-
}
|
148
|
-
allow(couchrest_db).to receive(:bulk_load).with(['1', '2'])
|
149
|
-
.and_return('rows' => [{'doc' => doc1}, {'doc' => doc2}])
|
150
|
-
|
151
|
-
db.load_document(['1', '2'])
|
152
|
-
db.load_document(['1', '2'])
|
153
|
-
|
154
|
-
expect(couchrest_db).to have_received(:bulk_load).with(['1', '2']).exactly(2).times
|
155
|
-
end
|
156
160
|
end
|
157
161
|
|
158
162
|
context 'when switching the database' do
|
data/spec/unit/database_spec.rb
CHANGED
@@ -92,6 +92,12 @@ describe CouchPotato::Database, 'load' do
|
|
92
92
|
db.load %w[1 2 3]
|
93
93
|
end
|
94
94
|
|
95
|
+
it 'does not request anything when nil is given' do
|
96
|
+
expect(db.load([nil])).to eq([])
|
97
|
+
|
98
|
+
expect(couchrest_db).not_to have_received(:bulk_load)
|
99
|
+
end
|
100
|
+
|
95
101
|
it 'returns only found documents' do
|
96
102
|
expect(db.load(%w[1 2 3]).size).to eq(2)
|
97
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_potato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|