Skip to content

Commit

Permalink
refactor(cursor): simplify implicit cursor session creation
Browse files Browse the repository at this point in the history
This code used to live in each of the cursor subclasses in order
to ensure sessions creation never happened in the core driver. Now
that we are merged, we can move this into the core cursor in order
to simply refactoring.

NODE-2065
  • Loading branch information
mbroadst authored and daprahamian committed Aug 13, 2019
1 parent fe2f57e commit 5c8bf32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions lib/command_cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ var methodsToInherit = [
'explain',
'isNotified',
'isKilled',
'_endSession',
'_initImplicitSession'
'_endSession'
];

// Only inherit the types we need
Expand Down
8 changes: 4 additions & 4 deletions lib/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,21 @@ if (SUPPORTS.ASYNC_ITERATOR) {

// Map core cursor _next method so we can apply mapping
Cursor.prototype._next = function() {
if (this._initImplicitSession) {
this._initImplicitSession();
}
return CoreCursor.prototype.next.apply(this, arguments);
};

for (let name in CoreCursor.prototype) {
Cursor.prototype[name] = CoreCursor.prototype[name];
}

Cursor.prototype._initImplicitSession = function() {
Cursor.prototype._initializeCursor = function(callback) {
// implicitly create a session if one has not been provided
if (!this.s.explicitlyIgnoreSession && !this.s.session && this.s.topology.hasSessionSupport()) {
this.s.session = this.s.topology.startSession({ owner: this });
this.cursorState.session = this.s.session;
}

CoreCursor.prototype._initializeCursor.apply(this, [callback]);
};

Cursor.prototype._endSession = function() {
Expand Down
4 changes: 0 additions & 4 deletions lib/operations/explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class ExplainOperation extends OperationBase {

execute() {
const cursor = this.cursor;

if (cursor._initImplicitSession) {
cursor._initImplicitSession();
}
return CoreCursor.prototype.next.apply(cursor, arguments);
}
}
Expand Down

0 comments on commit 5c8bf32

Please sign in to comment.