mongoid 7.0.10 → 7.0.11

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: 5ad9fbedf524c291d800a33349aed2f382c34bbe7b2db4417b7fc73f4c6b0ced
4
- data.tar.gz: 2dc25b9b97f8a9d56249ea690affb49537f3d8cc73d03e149abf5b3f9511f5bf
3
+ metadata.gz: 2db36cde93b00ddee6d916461da83d9bfaf6c0ee58e8a82fac70b506256c6892
4
+ data.tar.gz: 06a177507dd8099105f3d851c5b92d371ba9f8a399946944b1cea60c91ac1a34
5
5
  SHA512:
6
- metadata.gz: 86f6b6b3df1aaa98de5344f58e152b0a05b6f0ea21153e7fadd4a1d3b1ba74bed9a7b967ab608ce01dc2cb401c81e153f69569f5e8d19a96dcc953be27b16823
7
- data.tar.gz: e99a2501707a844f35a4eecc827163f871b77fd2f681e347e9bede2b0708dab8bdec0ce8520304f01f475c63cc33fc0216bd7d8b7e98556f5f6b696b8682ffe1
6
+ metadata.gz: 5f42d1faa7ae4f8815fe338eca85e76bbe5dc434a1dad4cbe6f883c0f4e5cd057d0a40898258306b238a10f80446699d70898b4b3dafa535f5fb1dfa3f5d71ba
7
+ data.tar.gz: e3bfe307cb9e3bed02a247a27ad68b8556672badb4b5162410ae2b675fb61a99f9ca6fb4926af77294ba0c11b514eeeb73cbe3beeb4edbe240ae438d49e837ec
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -161,14 +161,13 @@ module Mongoid
161
161
  private
162
162
 
163
163
  def process(result)
164
- @remaining -= result.returned_count if limited?
165
- @cursor_id = result.cursor_id
166
- @coll_name ||= result.namespace.sub("#{database.name}.", '') if result.namespace
167
- documents = result.documents
164
+ documents = super
165
+
168
166
  if @cursor_id.zero? && !@after_first_batch
169
167
  @cached_documents ||= []
170
168
  @cached_documents.concat(documents)
171
169
  end
170
+
172
171
  @after_first_batch = true
173
172
  documents
174
173
  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
- unless cursor = cached_cursor
231
- read_with_retry do
232
- server = server_selector.select_server(cluster)
233
- result = send_initial_query(server)
234
- if result.cursor_id == 0 || result.cursor_id.nil?
235
- cursor = CachedCursor.new(view, result, server)
236
- QueryCache.cache_table[cache_key] = cursor
237
- else
238
- cursor = Mongo::Cursor.new(view, result, server)
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 behaviour to the query cache for collections.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Mongoid
4
- VERSION = "7.0.10"
4
+ VERSION = "7.0.11"
5
5
  end
@@ -12,6 +12,7 @@ require "mongoid"
12
12
  require 'pp'
13
13
 
14
14
  require 'support/spec_config'
15
+ require "support/session_registry"
15
16
 
16
17
  unless SpecConfig.instance.ci?
17
18
  begin
@@ -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
@@ -540,7 +554,7 @@ describe Mongoid::QueryCache do
540
554
  Mongoid::QueryCache.enabled = true
541
555
  10.times { Band.create! }
542
556
 
543
- Band.batch_size(4).all.any?
557
+ Band.batch_size(4).all.to_a
544
558
  end
545
559
 
546
560
  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.0.10
4
+ version: 7.0.11
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-10-13 00:00:00.000000000 Z
32
+ date: 2020-11-06 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: activemodel
@@ -896,6 +896,7 @@ files:
896
896
  - spec/support/constraints.rb
897
897
  - spec/support/expectations.rb
898
898
  - spec/support/macros.rb
899
+ - spec/support/session_registry.rb
899
900
  - spec/support/spec_config.rb
900
901
  homepage: https://mongoid.org
901
902
  licenses:
@@ -1425,6 +1426,7 @@ test_files:
1425
1426
  - spec/mongoid_spec.rb
1426
1427
  - spec/lite_spec_helper.rb
1427
1428
  - spec/README.md
1429
+ - spec/support/session_registry.rb
1428
1430
  - spec/support/child_process_helper.rb
1429
1431
  - spec/support/constraints.rb
1430
1432
  - spec/support/macros.rb
metadata.gz.sig CHANGED
Binary file