-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Useful options and performance improvements for Pool #1779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,7 @@ function ConnectionConfig(options) { | |
this.user = options.user || undefined; | ||
this.password = options.password || undefined; | ||
this.database = options.database; | ||
this.connectTimeout = (options.connectTimeout === undefined) | ||
? (10 * 1000) | ||
: options.connectTimeout; | ||
this.connectTimeout = (options.connectTimeout === undefined) ? (10 * 1000) : options.connectTimeout; | ||
this.insecureAuth = options.insecureAuth || false; | ||
this.supportBigNumbers = options.supportBigNumbers || false; | ||
this.bigNumberStrings = options.bigNumberStrings || false; | ||
|
@@ -30,13 +28,9 @@ function ConnectionConfig(options) { | |
this.flags = options.flags || ''; | ||
this.queryFormat = options.queryFormat; | ||
this.pool = options.pool || undefined; | ||
this.ssl = (typeof options.ssl === 'string') | ||
? ConnectionConfig.getSSLProfile(options.ssl) | ||
: (options.ssl || false); | ||
this.ssl = (typeof options.ssl === 'string') ? ConnectionConfig.getSSLProfile(options.ssl) : (options.ssl || false); | ||
this.multipleStatements = options.multipleStatements || false; | ||
this.typeCast = (options.typeCast === undefined) | ||
? true | ||
: options.typeCast; | ||
this.typeCast = (options.typeCast === undefined) ? true : options.typeCast; | ||
|
||
if (this.timezone[0] === ' ') { | ||
// "+" is a url encoded char for space so it | ||
|
@@ -51,32 +45,42 @@ function ConnectionConfig(options) { | |
} | ||
|
||
this.maxPacketSize = 0; | ||
this.charsetNumber = (options.charset) | ||
? ConnectionConfig.getCharsetNumber(options.charset) | ||
: options.charsetNumber || Charsets.UTF8_GENERAL_CI; | ||
this.charsetNumber = (options.charset) ? ConnectionConfig.getCharsetNumber(options.charset) : options.charsetNumber || Charsets.UTF8_GENERAL_CI; | ||
|
||
// Set the client flags | ||
var defaultFlags = ConnectionConfig.getDefaultFlags(options); | ||
this.clientFlags = ConnectionConfig.mergeFlags(defaultFlags, options.flags); | ||
this.clientFlags = ConnectionConfig._getClientFlags(this.multipleStatements, this.flags); | ||
} | ||
|
||
var _clientFlagsCache = {}; | ||
|
||
ConnectionConfig._getClientFlags = function(multipleStatements, flags) { | ||
var key = flags + multipleStatements; | ||
|
||
if (_clientFlagsCache[key] === undefined) { | ||
var defaultFlags = ConnectionConfig.getDefaultFlags(multipleStatements); | ||
_clientFlagsCache[key] = ConnectionConfig.mergeFlags(defaultFlags, flags); | ||
} | ||
|
||
return _clientFlagsCache[key]; | ||
}; | ||
|
||
ConnectionConfig.mergeFlags = function mergeFlags(defaultFlags, userFlags) { | ||
var allFlags = ConnectionConfig.parseFlagList(defaultFlags); | ||
var newFlags = ConnectionConfig.parseFlagList(userFlags); | ||
|
||
// Merge the new flags | ||
for (var flag in newFlags) { | ||
if (allFlags[flag] !== false) { | ||
allFlags[flag] = newFlags[flag]; | ||
for (var newFlagKey in newFlags) { | ||
if (allFlags[newFlagKey] !== false) { | ||
allFlags[newFlagKey] = newFlags[newFlagKey]; | ||
} | ||
} | ||
|
||
// Build flags | ||
var flags = 0x0; | ||
for (var flag in allFlags) { | ||
if (allFlags[flag]) { | ||
for (var key in allFlags) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why rename this variable? Seems unrelated to the pull request. Please undo or explain how it fits into changing the pool. |
||
if (allFlags[key]) { | ||
// TODO: Throw here on some future release | ||
flags |= ClientConstants['CLIENT_' + flag] || 0x0; | ||
flags |= ClientConstants['CLIENT_' + key] || 0x0; | ||
} | ||
} | ||
|
||
|
@@ -93,7 +97,7 @@ ConnectionConfig.getCharsetNumber = function getCharsetNumber(charset) { | |
return num; | ||
}; | ||
|
||
ConnectionConfig.getDefaultFlags = function getDefaultFlags(options) { | ||
ConnectionConfig.getDefaultFlags = function getDefaultFlags(multipleStatements) { | ||
var defaultFlags = [ | ||
'-COMPRESS', // Compression protocol *NOT* supported | ||
'-CONNECT_ATTRS', // Does *NOT* send connection attributes in Protocol::HandshakeResponse41 | ||
|
@@ -114,7 +118,7 @@ ConnectionConfig.getDefaultFlags = function getDefaultFlags(options) { | |
'+TRANSACTIONS' // Expects status flags | ||
]; | ||
|
||
if (options && options.multipleStatements) { | ||
if (multipleStatements) { | ||
// May send multiple statements per COM_QUERY and COM_STMT_PREPARE | ||
defaultFlags.push('+MULTI_STATEMENTS'); | ||
} | ||
|
@@ -143,9 +147,7 @@ ConnectionConfig.parseFlagList = function parseFlagList(flagList) { | |
return allFlags; | ||
} | ||
|
||
var flags = !Array.isArray(flagList) | ||
? String(flagList || '').toUpperCase().split(/\s*,+\s*/) | ||
: flagList; | ||
var flags = !Array.isArray(flagList) ? String(flagList || '').toUpperCase().split(/\s*,+\s*/) : flagList; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please undo the format change to this line. |
||
|
||
for (var i = 0; i < flags.length; i++) { | ||
var flag = flags[i]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why rename this variable? Seems unrelated to the pull request. Please undo or explain how it fits into changing the pool.