Skip to content

Commit feec4ba

Browse files
mbroadstdaprahamian
authored andcommitted
refactor(cursor): deduplicate properties shared by base cursors
There are a number of properties stored on the `CoreCursor` that are duplicated in the private `s` member of the "native" cursor. This changeset removes duplication.
1 parent b3948aa commit feec4ba

File tree

9 files changed

+84
-88
lines changed

9 files changed

+84
-88
lines changed

lib/command_cursor.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,18 @@ CommandCursor.prototype.setReadPreference = function(readPreference) {
216216
* @return {CommandCursor}
217217
*/
218218
CommandCursor.prototype.batchSize = function(value) {
219-
if (this.s.state === CommandCursor.CLOSED || this.isDead())
219+
if (this.s.state === CommandCursor.CLOSED || this.isDead()) {
220220
throw MongoError.create({ message: 'Cursor is closed', driver: true });
221-
if (typeof value !== 'number')
221+
}
222+
223+
if (typeof value !== 'number') {
222224
throw MongoError.create({ message: 'batchSize requires an integer', driver: true });
223-
if (this.s.cmd.cursor) this.s.cmd.cursor.batchSize = value;
225+
}
226+
227+
if (this.cmd.cursor) {
228+
this.cmd.cursor.batchSize = value;
229+
}
230+
224231
this.setCursorBatchSize(value);
225232
return this;
226233
};
@@ -233,8 +240,9 @@ CommandCursor.prototype.batchSize = function(value) {
233240
*/
234241
CommandCursor.prototype.maxTimeMS = function(value) {
235242
if (this.s.topology.lastIsMaster().minWireVersion > 2) {
236-
this.s.cmd.maxTimeMS = value;
243+
this.cmd.maxTimeMS = value;
237244
}
245+
238246
return this;
239247
};
240248

0 commit comments

Comments
 (0)