mongoid 7.1.4 → 7.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongoid/query_cache.rb +47 -17
- data/lib/mongoid/version.rb +1 -1
- data/spec/lite_spec_helper.rb +1 -0
- data/spec/mongoid/query_cache_spec.rb +15 -1
- data/spec/support/session_registry.rb +50 -0
- metadata +4 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '06912d432d08b07e80bad71d5073cf2d5a4924f097cdefed959107c6cad245ef'
|
4
|
+
data.tar.gz: d6880896621095c3d3017207d9966f99c17f7aea9a1d7366746e287e4c2cea04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b9a2bcc459c5ae8f2d7dd5585e7c0c39869f6a860067ae4ab36c5df64efb524ef688d5ab087e1a52a9d6ea3101df66213ad607c62df7499e5706bcce3f0974c
|
7
|
+
data.tar.gz: cafe608ad57c0b91593bd570024c74aa6ed203f14e6ebe61b026601ef7c64ab8bc28d944a42e73aa6c1b1aea1510f83e9a64f869bee15ce549db2ade75e56295
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mongoid/query_cache.rb
CHANGED
@@ -163,14 +163,13 @@ module Mongoid
|
|
163
163
|
private
|
164
164
|
|
165
165
|
def process(result)
|
166
|
-
|
167
|
-
|
168
|
-
@coll_name ||= result.namespace.sub("#{database.name}.", '') if result.namespace
|
169
|
-
documents = result.documents
|
166
|
+
documents = super
|
167
|
+
|
170
168
|
if @cursor_id.zero? && !@after_first_batch
|
171
169
|
@cached_documents ||= []
|
172
170
|
@cached_documents.concat(documents)
|
173
171
|
end
|
172
|
+
|
174
173
|
@after_first_batch = true
|
175
174
|
documents
|
176
175
|
end
|
@@ -224,34 +223,39 @@ module Mongoid
|
|
224
223
|
#
|
225
224
|
# @since 5.0.0
|
226
225
|
def each
|
227
|
-
if system_collection? || !QueryCache.enabled?
|
226
|
+
if system_collection? || !QueryCache.enabled? || (respond_to?(:write?, true) && write?)
|
228
227
|
super
|
229
228
|
else
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
229
|
+
@cursor = nil
|
230
|
+
unless @cursor = cached_cursor
|
231
|
+
|
232
|
+
if driver_supports_cursor_sessions?
|
233
|
+
session = client.send(:get_session, @options)
|
234
|
+
read_with_retry(session, server_selector) do |server|
|
235
|
+
result = send_initial_query(server, session)
|
236
|
+
@cursor = get_cursor(result, server, session)
|
237
|
+
end
|
238
|
+
else
|
239
|
+
read_with_retry do
|
240
|
+
server = server_selector.select_server(cluster)
|
241
|
+
result = send_initial_query(server)
|
242
|
+
@cursor = get_cursor(result, server)
|
239
243
|
end
|
240
244
|
end
|
241
245
|
end
|
242
246
|
|
243
247
|
if block_given?
|
244
248
|
if limit && limit != -1
|
245
|
-
cursor.to_a[0...limit].each do |doc|
|
249
|
+
@cursor.to_a[0...limit].each do |doc|
|
246
250
|
yield doc
|
247
251
|
end
|
248
252
|
else
|
249
|
-
cursor.each do |doc|
|
253
|
+
@cursor.each do |doc|
|
250
254
|
yield doc
|
251
255
|
end
|
252
256
|
end
|
253
257
|
else
|
254
|
-
cursor
|
258
|
+
@cursor.to_enum
|
255
259
|
end
|
256
260
|
end
|
257
261
|
end
|
@@ -266,6 +270,26 @@ module Mongoid
|
|
266
270
|
cursor || QueryCache.cache_table[cache_key]
|
267
271
|
end
|
268
272
|
|
273
|
+
def get_cursor(result, server, session = nil)
|
274
|
+
if result.cursor_id == 0 || result.cursor_id.nil?
|
275
|
+
cursor = if session
|
276
|
+
CachedCursor.new(view, result, server, session: session)
|
277
|
+
else
|
278
|
+
CachedCursor.new(view, result, server)
|
279
|
+
end
|
280
|
+
|
281
|
+
QueryCache.cache_table[cache_key] = cursor
|
282
|
+
else
|
283
|
+
cursor = if session
|
284
|
+
Mongo::Cursor.new(view, result, server, session: session)
|
285
|
+
else
|
286
|
+
Mongo::Cursor.new(view, result, server)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
cursor
|
291
|
+
end
|
292
|
+
|
269
293
|
def cache_key
|
270
294
|
[ collection.namespace, selector, limit, skip, sort, projection, collation ]
|
271
295
|
end
|
@@ -273,6 +297,12 @@ module Mongoid
|
|
273
297
|
def system_collection?
|
274
298
|
collection.namespace =~ /\Asystem./
|
275
299
|
end
|
300
|
+
|
301
|
+
def driver_supports_cursor_sessions?
|
302
|
+
# Driver versions 2.9 and newer support passing in a session to the
|
303
|
+
# cursor object.
|
304
|
+
(Mongo::VERSION.split('.').map(&:to_i) <=> [2, 9, 0]) > 0
|
305
|
+
end
|
276
306
|
end
|
277
307
|
|
278
308
|
# Adds behavior to the query cache for collections.
|
data/lib/mongoid/version.rb
CHANGED
data/spec/lite_spec_helper.rb
CHANGED
@@ -10,6 +10,20 @@ describe Mongoid::QueryCache do
|
|
10
10
|
Mongoid::QueryCache.cache { spec.run }
|
11
11
|
end
|
12
12
|
|
13
|
+
before(:all) do
|
14
|
+
# It is likely that there are other session leaks in the driver
|
15
|
+
# and/or Mongoid that are unrelated to the query cache. Clear the
|
16
|
+
# SessionRegistry at the start of these tests in order to detect leaks that
|
17
|
+
# occur only within the scope of these tests.
|
18
|
+
#
|
19
|
+
# Other session leaks will be detected and addressed as part of RUBY-2391.
|
20
|
+
SessionRegistry.instance.clear_registry
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
SessionRegistry.instance.verify_sessions_ended!
|
25
|
+
end
|
26
|
+
|
13
27
|
context 'when iterating over objects sharing the same base' do
|
14
28
|
|
15
29
|
let(:server) do
|
@@ -543,7 +557,7 @@ describe Mongoid::QueryCache do
|
|
543
557
|
Mongoid::QueryCache.enabled = true
|
544
558
|
10.times { Band.create! }
|
545
559
|
|
546
|
-
Band.batch_size(4).all.
|
560
|
+
Band.batch_size(4).all.to_a
|
547
561
|
end
|
548
562
|
|
549
563
|
it 'does not cache the result' do
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Mongo
|
4
|
+
class Client
|
5
|
+
alias :get_session_without_tracking :get_session
|
6
|
+
|
7
|
+
def get_session(options = {})
|
8
|
+
get_session_without_tracking(options).tap do |session|
|
9
|
+
SessionRegistry.instance.register(session)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Session
|
15
|
+
alias :end_session_without_tracking :end_session
|
16
|
+
|
17
|
+
def end_session
|
18
|
+
SessionRegistry.instance.unregister(self)
|
19
|
+
end_session_without_tracking
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
class SessionRegistry
|
26
|
+
include Singleton
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@registry = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def register(session)
|
33
|
+
@registry[session.session_id] = session if session
|
34
|
+
end
|
35
|
+
|
36
|
+
def unregister(session)
|
37
|
+
@registry.delete(session.session_id)
|
38
|
+
end
|
39
|
+
|
40
|
+
def verify_sessions_ended!
|
41
|
+
unless @registry.empty?
|
42
|
+
sessions = @registry.map { |_, session| session }
|
43
|
+
raise "Session registry contains live sessions: #{sessions.join(', ')}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def clear_registry
|
48
|
+
@registry = {}
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.1.
|
4
|
+
version: 7.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
gpvfPNWMwyBDlHaNS3GfO6cRRxBOvEG05GUCsvtTY4Bpe8yjE64wg1ymb47LMOnv
|
30
30
|
Qb1lGORmf/opg45mluKUYl7pQNZHD0d3
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2020-
|
32
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: activemodel
|
@@ -929,6 +929,7 @@ files:
|
|
929
929
|
- spec/support/helpers.rb
|
930
930
|
- spec/support/lite_constraints.rb
|
931
931
|
- spec/support/macros.rb
|
932
|
+
- spec/support/session_registry.rb
|
932
933
|
- spec/support/shared/time.rb
|
933
934
|
- spec/support/spec_config.rb
|
934
935
|
homepage: https://mongoid.org
|
@@ -1489,6 +1490,7 @@ test_files:
|
|
1489
1490
|
- spec/lite_spec_helper.rb
|
1490
1491
|
- spec/README.md
|
1491
1492
|
- spec/support/helpers.rb
|
1493
|
+
- spec/support/session_registry.rb
|
1492
1494
|
- spec/support/child_process_helper.rb
|
1493
1495
|
- spec/support/constraints.rb
|
1494
1496
|
- spec/support/lite_constraints.rb
|
metadata.gz.sig
CHANGED
Binary file
|