mongoid 7.1.4 → 7.1.5

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: 16518b942d2280aa5a81476d27709c2242f98ad559a2cea776c23369f9951d58
4
- data.tar.gz: 243b7a7b9e0991f5feb7c3e8ae514e650915052c93b78c31fcbe8d8308e7743a
3
+ metadata.gz: '06912d432d08b07e80bad71d5073cf2d5a4924f097cdefed959107c6cad245ef'
4
+ data.tar.gz: d6880896621095c3d3017207d9966f99c17f7aea9a1d7366746e287e4c2cea04
5
5
  SHA512:
6
- metadata.gz: '07539688736c17c7d33b8dfea04e7c5d9d8295b176358be200fd5cc0793c40902e54704697c75a6bf08930f418891b032ae0f0f0dbb090635590c277ca2aabce'
7
- data.tar.gz: ed2a4140a29a5dfd12328a34363af63280661048c15c7b34b32905bdec493822e7377cb206407a7ba99298b27ef158785ba5ec92b5ef93641a95de923c539022
6
+ metadata.gz: 9b9a2bcc459c5ae8f2d7dd5585e7c0c39869f6a860067ae4ab36c5df64efb524ef688d5ab087e1a52a9d6ea3101df66213ad607c62df7499e5706bcce3f0974c
7
+ data.tar.gz: cafe608ad57c0b91593bd570024c74aa6ed203f14e6ebe61b026601ef7c64ab8bc28d944a42e73aa6c1b1aea1510f83e9a64f869bee15ce549db2ade75e56295
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -163,14 +163,13 @@ module Mongoid
163
163
  private
164
164
 
165
165
  def process(result)
166
- @remaining -= result.returned_count if limited?
167
- @cursor_id = result.cursor_id
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
- 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 behavior to the query cache for collections.
@@ -2,5 +2,5 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  module Mongoid
5
- VERSION = "7.1.4"
5
+ VERSION = "7.1.5"
6
6
  end
@@ -16,6 +16,7 @@ require 'pp'
16
16
 
17
17
  require 'support/spec_config'
18
18
  require 'support/lite_constraints'
19
+ require "support/session_registry"
19
20
 
20
21
  unless SpecConfig.instance.ci?
21
22
  begin
@@ -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.any?
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
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-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
@@ -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