Skip to content

Commit b32acec

Browse files
committed
RUBY-1028: Improve performance of reply protocol upconverter
1 parent 8249b70 commit b32acec

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

lib/mongo/protocol/reply.rb

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ def op_code
101101
# @since 2.1.0
102102
class Upconverter
103103

104+
# Next batch constant.
105+
#
106+
# @since 2.1.0
107+
NEXT_BATCH = 'nextBatch'.freeze
108+
109+
# First batch constant.
110+
#
111+
# @since 2.1.0
112+
FIRST_BATCH = 'firstBatch'.freeze
113+
114+
# Cursor field constant.
115+
#
116+
# @since 2.1.0
117+
CURSOR = 'cursor'.freeze
118+
119+
# Id field constant.
120+
#
121+
# @since 2.1.0
122+
ID = 'id'.freeze
123+
104124
# @return [ Array<BSON::Document> ] documents The documents.
105125
attr_reader :documents
106126

@@ -141,20 +161,20 @@ def command
141161
private
142162

143163
def batch_field
144-
starting_from > 0 ? 'nextBatch' : 'firstBatch'
164+
starting_from > 0 ? NEXT_BATCH : FIRST_BATCH
145165
end
146166

147167
def command?
148-
!documents.empty? && documents.first.key?('ok')
168+
!documents.empty? && documents.first.key?(Operation::Result::OK)
149169
end
150170

151171
def find_command
152172
document = BSON::Document.new
153173
cursor_document = BSON::Document.new
154-
cursor_document.store('id', cursor_id)
174+
cursor_document.store(ID, cursor_id)
155175
cursor_document.store(batch_field, documents)
156-
document.store('ok', 1)
157-
document.store('cursor', cursor_document)
176+
document.store(Operation::Result::OK, 1)
177+
document.store(CURSOR, cursor_document)
158178
document
159179
end
160180

0 commit comments

Comments
 (0)