不要怂,就是干,撸起袖子干!

You need to sign in or sign up before continuing.
Commit f09f2de1 by Mick Hansen Committed by Jan Aagaard Meier

provide option (not exposed currently) to turn off mysql query queuing

1 parent 4a7b6084
Showing with 46 additions and 16 deletions
......@@ -14,6 +14,8 @@ module.exports = (function() {
this.activeQueue = []
this.maxConcurrentQueries = (this.config.maxConcurrentQueries || 50)
this.poolCfg = this.config.pool
this.pendingQueries = 0;
this.useQueue = false;
var self = this
......@@ -47,41 +49,69 @@ module.exports = (function() {
})
}
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype)
Utils._.extend(ConnectorManager.prototype, require("../connector-manager").prototype);
var isConnecting = false
var isConnecting = false;
ConnectorManager.prototype.query = function(sql, callee, options) {
if(!this.isConnected && !this.pool) this.connect()
if (!this.isConnected && !this.pool) this.connect();
if (this.useQueue) {
var queueItem = {
query: new Query(this.client, this.sequelize, callee, options || {}),
sql: sql
};
enqueue.call(this, queueItem);
return queueItem.query;
}
enqueue.call(this, queueItem)
var self = this, query = new Query(this.client, this.sequelize, callee, options || {});
this.pendingQueries++;
query.done(function() {
self.pendingQueries--;
if (self.pool) self.pool.release(query.client);
else {
if (self.pendingQueries === 0) {
setTimeout(function() {
self.pendingQueries === 0 && self.disconnect.call(self);
}, 1);
}
}
});
if (!this.pool) query.run(sql);
else {
this.pool.acquire(function(err, client) {
if (err) return query.emit('error', err);
return queueItem.query
query.client = client;
query.run(sql);
return;
});
}
return query;
};
ConnectorManager.prototype.connect = function() {
var self = this
var self = this;
// in case database is slow to connect, prevent orphaning the client
if (this.isConnecting || this.pool) {
return
return;
}
connect.call(self, function(err, client) {
self.client = client
return
})
return
}
self.client = client;
return;
});
return;
};
ConnectorManager.prototype.disconnect = function() {
if (this.client)
disconnect.call(this, this.client)
return
}
if (this.client) disconnect.call(this, this.client);
return;
};
// private
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!