couch_potato 1.16.0 → 1.17.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
  SHA256:
3
- metadata.gz: 3fd11db6b5bb37ef9b0d12115ae4586f8f0ec8afff586e7a2b381e1839af0196
4
- data.tar.gz: 7f03e40ec9297bb669f28559e251b72f5b8e849010b8861d992c75c5ed7737a3
3
+ metadata.gz: a78d19f65a75932bb6f60639fc9ad3dff0151e9c7de7f8cbc31e1b61038f7fa8
4
+ data.tar.gz: c5383ffd3db50bd45d727a84b62588dcd70d6ea3d07ac96559e1318c145fb057
5
5
  SHA512:
6
- metadata.gz: 72bc1831a2b773d3f64682f1fbe20fb10acccad204fd057e92676c53fe03f5f56b462c02905b3f3ee52ddb6fa640f6dfe6a05a3f1e1aeb8e750eaecb76922a38
7
- data.tar.gz: 4a49349375cabe65b465c99336e3c0b05564d0b720faa6ae4d956633809ea52d6a73119118c7bc923d0ffde0aefd5af93f3fbdc587fed89696942b05ce421025
6
+ metadata.gz: 38aa7ce10b0f12429789ecc0f25e34b276f98eadedac900f2ea18b7c1845549be28becb624d4da1c89506d814fa403b7f9647f960f3be534ac47b02c839f6866
7
+ data.tar.gz: e0b48a96f9a485d0765b066b5e5bca043058b85af246775abdf2bf3afb598bf691b09ae156182b9ecf1ff9dcc0acdee3bb5cc899a8722d0a75bdff9ded965b7b
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Changes
2
2
 
3
+ # 1.17.0
4
+
5
+ - filter out nil ids for loading multiple documents
6
+ - cache nil documents
7
+
3
8
  # 1.16.0
4
9
 
5
10
  - add payload to ActiveSupport instrumentation calls
@@ -149,7 +149,7 @@ module CouchPotato
149
149
 
150
150
  cached = cache && cache[id]
151
151
  if cache
152
- if cached
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 if 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] }
@@ -1,4 +1,4 @@
1
1
  module CouchPotato
2
- VERSION = '1.16.0'.freeze
2
+ VERSION = '1.17.0'.freeze
3
3
  RSPEC_VERSION = '4.1.0'.freeze
4
4
  end
@@ -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
@@ -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.16.0
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-02 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel