This commit is contained in:
Jonasz Bigda
2023-03-25 21:51:42 +01:00
parent 0db1d5117e
commit b332e9ceb0
1044 changed files with 37502 additions and 63938 deletions

View File

@@ -27,10 +27,6 @@ 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 };
}
@@ -40,7 +36,7 @@ function Collection(name, conn, opts) {
this.collectionName = name;
this.conn = conn;
this.queue = [];
this.buffer = this.opts.bufferCommands;
this.buffer = true;
this.emitter = new EventEmitter();
if (STATES.connected === this.conn.readyState) {
@@ -93,7 +89,7 @@ Collection.prototype.onOpen = function() {
*/
Collection.prototype.onClose = function(force) {
if (this.opts.bufferCommands && !force) {
if (this._shouldBufferCommands() && !force) {
this.buffer = true;
}
};
@@ -112,6 +108,23 @@ Collection.prototype.addQueue = function(name, args) {
return this;
};
/**
* Removes a queued method
*
* @param {String} name name of the method to queue
* @param {Array} args arguments to pass to the method when executed
* @api private
*/
Collection.prototype.removeQueue = function(name, args) {
const index = this.queue.findIndex(v => v[0] === name && v[1] === args);
if (index === -1) {
return false;
}
this.queue.splice(index, 1);
return true;
};
/**
* Executes all queued methods and clears the queue.
*
@@ -128,7 +141,7 @@ Collection.prototype.doQueue = function() {
}
this.queue = [];
const _this = this;
process.nextTick(function() {
immediate(function() {
_this.emitter.emit('queue');
});
return this;
@@ -147,7 +160,7 @@ Collection.prototype.ensureIndex = function() {
*/
Collection.prototype.createIndex = function() {
throw new Error('Collection#ensureIndex unimplemented by driver');
throw new Error('Collection#createIndex unimplemented by driver');
};
/**
@@ -262,6 +275,46 @@ Collection.prototype.watch = function() {
throw new Error('Collection#watch unimplemented by driver');
};
/*!
* ignore
*/
Collection.prototype._shouldBufferCommands = function _shouldBufferCommands() {
const opts = this.opts;
if (opts.bufferCommands != null) {
return opts.bufferCommands;
}
if (opts && opts.schemaUserProvidedOptions != null && opts.schemaUserProvidedOptions.bufferCommands != null) {
return opts.schemaUserProvidedOptions.bufferCommands;
}
return this.conn._shouldBufferCommands();
};
/*!
* ignore
*/
Collection.prototype._getBufferTimeoutMS = function _getBufferTimeoutMS() {
const conn = this.conn;
const opts = this.opts;
if (opts.bufferTimeoutMS != null) {
return opts.bufferTimeoutMS;
}
if (opts && opts.schemaUserProvidedOptions != null && opts.schemaUserProvidedOptions.bufferTimeoutMS != null) {
return opts.schemaUserProvidedOptions.bufferTimeoutMS;
}
if (conn.config.bufferTimeoutMS != null) {
return conn.config.bufferTimeoutMS;
}
if (conn.base != null && conn.base.get('bufferTimeoutMS') != null) {
return conn.base.get('bufferTimeoutMS');
}
return 10000;
};
/*!
* Module exports.
*/