mongoid 6.4.7 → 6.4.8
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongoid/query_cache.rb +52 -18
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -0
- 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: b8c453904dce4061c6cd88c36e21f3514fb778b37976ffd12e985aaf80fc2b98
|
4
|
+
data.tar.gz: d10421a146387851daa6a9c27184b48da1cc50d96a946bce0851aa69fd56c9a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c0e672470d68faab3afc70e65524baa771801b46bbbb51b831a5cc709baf6df4ed7f0d81aed2dd5d0c3e3cf6730166da9bc8345b33577298f4438ec6c11fca3
|
7
|
+
data.tar.gz: 2008465437ba6eafe50235b22204df40b560b8e3bd27d064e97912c3249f5443af2ad1016c9a545d9d487abc6c1b38835624090a6d9165d06f9c4e676b561a23
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mongoid/query_cache.rb
CHANGED
@@ -159,11 +159,14 @@ module Mongoid
|
|
159
159
|
private
|
160
160
|
|
161
161
|
def process(result)
|
162
|
-
|
163
|
-
|
164
|
-
@
|
165
|
-
|
166
|
-
|
162
|
+
documents = super
|
163
|
+
|
164
|
+
if @cursor_id.zero? && !@after_first_batch
|
165
|
+
@cached_documents ||= []
|
166
|
+
@cached_documents.concat(documents)
|
167
|
+
end
|
168
|
+
|
169
|
+
@after_first_batch = true
|
167
170
|
documents
|
168
171
|
end
|
169
172
|
end
|
@@ -218,34 +221,39 @@ module Mongoid
|
|
218
221
|
#
|
219
222
|
# @since 5.0.0
|
220
223
|
def each
|
221
|
-
if system_collection? || !QueryCache.enabled?
|
224
|
+
if system_collection? || !QueryCache.enabled? || (respond_to?(:write?, true) && write?)
|
222
225
|
super
|
223
226
|
else
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
227
|
+
@cursor = nil
|
228
|
+
unless @cursor = cached_cursor
|
229
|
+
|
230
|
+
if driver_supports_cursor_sessions?
|
231
|
+
session = client.send(:get_session, @options)
|
232
|
+
read_with_retry(session, server_selector) do |server|
|
233
|
+
result = send_initial_query(server, session)
|
234
|
+
@cursor = get_cursor(result, server, session)
|
235
|
+
end
|
236
|
+
else
|
237
|
+
read_with_retry do
|
238
|
+
server = server_selector.select_server(cluster)
|
239
|
+
result = send_initial_query(server)
|
240
|
+
@cursor = get_cursor(result, server)
|
233
241
|
end
|
234
242
|
end
|
235
243
|
end
|
236
244
|
|
237
245
|
if block_given?
|
238
246
|
if limit && limit != -1
|
239
|
-
cursor.to_a[0...limit].each do |doc|
|
247
|
+
@cursor.to_a[0...limit].each do |doc|
|
240
248
|
yield doc
|
241
249
|
end
|
242
250
|
else
|
243
|
-
cursor.each do |doc|
|
251
|
+
@cursor.each do |doc|
|
244
252
|
yield doc
|
245
253
|
end
|
246
254
|
end
|
247
255
|
else
|
248
|
-
cursor
|
256
|
+
@cursor.to_enum
|
249
257
|
end
|
250
258
|
end
|
251
259
|
end
|
@@ -260,6 +268,26 @@ module Mongoid
|
|
260
268
|
cursor || QueryCache.cache_table[cache_key]
|
261
269
|
end
|
262
270
|
|
271
|
+
def get_cursor(result, server, session = nil)
|
272
|
+
if result.cursor_id == 0 || result.cursor_id.nil?
|
273
|
+
cursor = if session
|
274
|
+
CachedCursor.new(view, result, server, session: session)
|
275
|
+
else
|
276
|
+
CachedCursor.new(view, result, server)
|
277
|
+
end
|
278
|
+
|
279
|
+
QueryCache.cache_table[cache_key] = cursor
|
280
|
+
else
|
281
|
+
cursor = if session
|
282
|
+
Mongo::Cursor.new(view, result, server, session: session)
|
283
|
+
else
|
284
|
+
Mongo::Cursor.new(view, result, server)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
cursor
|
289
|
+
end
|
290
|
+
|
263
291
|
def cache_key
|
264
292
|
[ collection.namespace, selector, limit, skip, sort, projection, collation ]
|
265
293
|
end
|
@@ -267,6 +295,12 @@ module Mongoid
|
|
267
295
|
def system_collection?
|
268
296
|
collection.namespace =~ /^system./
|
269
297
|
end
|
298
|
+
|
299
|
+
def driver_supports_cursor_sessions?
|
300
|
+
# Driver versions 2.9 and newer support passing in a session to the
|
301
|
+
# cursor object.
|
302
|
+
(Mongo::VERSION.split('.').map(&:to_i) <=> [2, 9, 0]) > 0
|
303
|
+
end
|
270
304
|
end
|
271
305
|
|
272
306
|
# Adds behaviour to the query cache for collections.
|
data/lib/mongoid/version.rb
CHANGED
@@ -7,6 +7,20 @@ describe Mongoid::QueryCache do
|
|
7
7
|
Mongoid::QueryCache.cache { spec.run }
|
8
8
|
end
|
9
9
|
|
10
|
+
before(:all) do
|
11
|
+
# It is likely that there are other session leaks in the driver
|
12
|
+
# and/or Mongoid that are unrelated to the query cache. Clear the
|
13
|
+
# SessionRegistry at the start of these tests in order to detect leaks that
|
14
|
+
# occur only within the scope of these tests.
|
15
|
+
#
|
16
|
+
# Other session leaks will be detected and addressed as part of RUBY-2391.
|
17
|
+
SessionRegistry.instance.clear_registry
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
SessionRegistry.instance.verify_sessions_ended!
|
22
|
+
end
|
23
|
+
|
10
24
|
context 'when iterating over objects sharing the same base' do
|
11
25
|
|
12
26
|
let(:server) do
|
data/spec/spec_helper.rb
CHANGED
@@ -38,6 +38,7 @@ require 'support/macros'
|
|
38
38
|
require 'support/spec_config'
|
39
39
|
require 'support/cluster_config'
|
40
40
|
require 'support/constraints'
|
41
|
+
require 'support/session_registry'
|
41
42
|
|
42
43
|
# Give MongoDB time to start up on the travis ci environment.
|
43
44
|
if (ENV['CI'] == 'travis' || ENV['CI'] == 'evergreen')
|
@@ -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: 6.4.
|
4
|
+
version: 6.4.8
|
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
|
@@ -861,6 +861,7 @@ files:
|
|
861
861
|
- spec/support/constraints.rb
|
862
862
|
- spec/support/expectations.rb
|
863
863
|
- spec/support/macros.rb
|
864
|
+
- spec/support/session_registry.rb
|
864
865
|
- spec/support/spec_config.rb
|
865
866
|
homepage: http://mongoid.org
|
866
867
|
licenses:
|
@@ -1356,6 +1357,7 @@ test_files:
|
|
1356
1357
|
- spec/config/mongoid.yml
|
1357
1358
|
- spec/integration/document_spec.rb
|
1358
1359
|
- spec/mongoid_spec.rb
|
1360
|
+
- spec/support/session_registry.rb
|
1359
1361
|
- spec/support/constraints.rb
|
1360
1362
|
- spec/support/macros.rb
|
1361
1363
|
- spec/support/expectations.rb
|
metadata.gz.sig
CHANGED
Binary file
|