Refactoring day1

This commit is contained in:
2020-08-20 20:27:14 +02:00
parent 6aceefeb2f
commit b907489a75
481 changed files with 5321 additions and 5616 deletions

View File

@@ -27,6 +27,10 @@ function Collection(name, conn, opts) {
opts.capped = {};
}
opts.bufferCommands = undefined === opts.bufferCommands
? true
: opts.bufferCommands;
if (typeof opts.capped === 'number') {
opts.capped = { size: opts.capped };
}
@@ -36,7 +40,7 @@ function Collection(name, conn, opts) {
this.collectionName = name;
this.conn = conn;
this.queue = [];
this.buffer = true;
this.buffer = this.opts.bufferCommands;
this.emitter = new EventEmitter();
if (STATES.connected === this.conn.readyState) {
@@ -89,7 +93,7 @@ Collection.prototype.onOpen = function() {
*/
Collection.prototype.onClose = function(force) {
if (this._shouldBufferCommands() && !force) {
if (this.opts.bufferCommands && !force) {
this.buffer = true;
}
};
@@ -258,29 +262,6 @@ Collection.prototype.watch = function() {
throw new Error('Collection#watch unimplemented by driver');
};
/*!
* ignore
*/
Collection.prototype._shouldBufferCommands = function _shouldBufferCommands() {
const conn = this.conn;
const opts = this.opts;
if (opts.bufferCommands != null) {
return opts.bufferCommands;
}
if (opts && opts.schemaUserProvidedOptions != null && opts.schemaUserProvidedOptions.bufferCommands != null) {
return opts.schemaUserProvidedOptions.bufferCommands;
}
if (conn.config.bufferCommands != null) {
return conn.config.bufferCommands;
}
if (conn.base != null && conn.base.get('bufferCommands') != null) {
return conn.base.get('bufferCommands');
}
return true;
};
/*!
* Module exports.
*/