1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

chore: remove let due to performance reasons

This commit is contained in:
Ruben Bridgewater
2017-05-26 12:45:34 +02:00
parent 065eebad9c
commit 6794478066
5 changed files with 18 additions and 18 deletions

View File

@@ -296,7 +296,7 @@ RedisClient.prototype.warn = function (msg) {
RedisClient.prototype.flushAndError = function (errorAttributes, options) { RedisClient.prototype.flushAndError = function (errorAttributes, options) {
options = options || {} options = options || {}
const queueNames = options.queues || ['commandQueue', 'offlineQueue'] // Flush the commandQueue first to keep the order intact const queueNames = options.queues || ['commandQueue', 'offlineQueue'] // Flush the commandQueue first to keep the order intact
for (let i = 0; i < queueNames.length; i++) { for (var i = 0; i < queueNames.length; i++) {
// If the command was fired it might have been processed so far // If the command was fired it might have been processed so far
if (queueNames[i] === 'commandQueue') { if (queueNames[i] === 'commandQueue') {
errorAttributes.message += ' It might have been processed.' errorAttributes.message += ' It might have been processed.'
@@ -304,7 +304,7 @@ RedisClient.prototype.flushAndError = function (errorAttributes, options) {
errorAttributes.message = errorAttributes.message.replace(' It might have been processed.', '') errorAttributes.message = errorAttributes.message.replace(' It might have been processed.', '')
} }
// Don't flush everything from the queue // Don't flush everything from the queue
for (let commandObj = this[queueNames[i]].shift(); commandObj; commandObj = this[queueNames[i]].shift()) { for (var commandObj = this[queueNames[i]].shift(); commandObj; commandObj = this[queueNames[i]].shift()) {
const err = new errorClasses.AbortError(errorAttributes) const err = new errorClasses.AbortError(errorAttributes)
if (commandObj.error) { if (commandObj.error) {
err.stack = err.stack + commandObj.error.stack.replace(/^Error.*?\n/, '\n') err.stack = err.stack + commandObj.error.stack.replace(/^Error.*?\n/, '\n')
@@ -456,7 +456,7 @@ RedisClient.prototype.onInfoCmd = function (res) {
} }
} }
let retryTime = +this.serverInfo.loading_eta_seconds * 1000 var retryTime = +this.serverInfo.loading_eta_seconds * 1000
if (retryTime > 1000) { if (retryTime > 1000) {
retryTime = 1000 retryTime = 1000
} }
@@ -477,7 +477,7 @@ RedisClient.prototype.readyCheck = function () {
} }
RedisClient.prototype.sendOfflineQueue = function () { RedisClient.prototype.sendOfflineQueue = function () {
for (let commandObj = this.offlineQueue.shift(); commandObj; commandObj = this.offlineQueue.shift()) { for (var commandObj = this.offlineQueue.shift(); commandObj; commandObj = this.offlineQueue.shift()) {
debug('Sending offline command: %s', commandObj.command) debug('Sending offline command: %s', commandObj.command)
this.internalSendCommand(commandObj) this.internalSendCommand(commandObj)
} }
@@ -648,8 +648,8 @@ function subscribeUnsubscribe (self, reply, type) {
if (commandObj.argsLength === 1 || self.subCommandsLeft === 1 || commandObj.argsLength === 0 && (count === 0 || channel === null)) { if (commandObj.argsLength === 1 || self.subCommandsLeft === 1 || commandObj.argsLength === 0 && (count === 0 || channel === null)) {
if (count === 0) { // unsubscribed from all channels if (count === 0) { // unsubscribed from all channels
let runningCommand var runningCommand
let i = 1 var i = 1
self.pubSubMode = 0 // Deactivating pub sub mode self.pubSubMode = 0 // Deactivating pub sub mode
// This should be a rare case and therefore handling it this way should be good performance wise for the general case // This should be a rare case and therefore handling it this way should be good performance wise for the general case
for (runningCommand = self.commandQueue.get(i); runningCommand !== undefined; runningCommand = self.commandQueue.get(i)) { for (runningCommand = self.commandQueue.get(i); runningCommand !== undefined; runningCommand = self.commandQueue.get(i)) {
@@ -699,7 +699,7 @@ RedisClient.prototype.returnReply = function (reply) {
// As this is not the average use case and monitor is expensive anyway, let's change the code here, to improve // As this is not the average use case and monitor is expensive anyway, let's change the code here, to improve
// the average performance of all other commands in case of no monitor mode // the average performance of all other commands in case of no monitor mode
if (this.monitoring) { if (this.monitoring) {
let replyStr var replyStr
if (this.buffers && Buffer.isBuffer(reply)) { if (this.buffers && Buffer.isBuffer(reply)) {
replyStr = reply.toString() replyStr = reply.toString()
} else { } else {
@@ -731,8 +731,8 @@ RedisClient.prototype.returnReply = function (reply) {
} }
function handleOfflineCommand (self, commandObj) { function handleOfflineCommand (self, commandObj) {
let command = commandObj.command var command = commandObj.command
let err, msg var err, msg
if (self.closing || !self.enableOfflineQueue) { if (self.closing || !self.enableOfflineQueue) {
command = command.toUpperCase() command = command.toUpperCase()
if (!self.closing) { if (!self.closing) {
@@ -793,8 +793,8 @@ RedisClient.prototype.internalSendCommand = function (commandObj) {
} }
RedisClient.prototype.writeStrings = function () { RedisClient.prototype.writeStrings = function () {
let str = '' var str = ''
for (let command = this.pipelineQueue.shift(); command; command = this.pipelineQueue.shift()) { for (var command = this.pipelineQueue.shift(); command; command = this.pipelineQueue.shift()) {
// Write to stream if the string is bigger than 4mb. The biggest string may be Math.pow(2, 28) - 15 chars long // Write to stream if the string is bigger than 4mb. The biggest string may be Math.pow(2, 28) - 15 chars long
if (str.length + command.length > 4 * 1024 * 1024) { if (str.length + command.length > 4 * 1024 * 1024) {
this.shouldBuffer = !this.stream.write(str) this.shouldBuffer = !this.stream.write(str)
@@ -808,7 +808,7 @@ RedisClient.prototype.writeStrings = function () {
} }
RedisClient.prototype.writeBuffers = function () { RedisClient.prototype.writeBuffers = function () {
for (let command = this.pipelineQueue.shift(); command; command = this.pipelineQueue.shift()) { for (var command = this.pipelineQueue.shift(); command; command = this.pipelineQueue.shift()) {
this.shouldBuffer = !this.stream.write(command) this.shouldBuffer = !this.stream.write(command)
} }
} }

View File

@@ -16,7 +16,7 @@ class AbortError extends RedisError {
if (stack || stack === undefined) { if (stack || stack === undefined) {
Error.captureStackTrace(this, AbortError) Error.captureStackTrace(this, AbortError)
} }
for (let keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) { for (var keys = Object.keys(obj), key = keys.pop(); key; key = keys.pop()) {
this[key] = obj[key] this[key] = obj[key]
} }
} }

View File

@@ -117,7 +117,7 @@ function infoCallback (self) {
const lines = res.toString().split('\r\n') const lines = res.toString().split('\r\n')
var line, parts, subParts var line, parts, subParts
for (let i = 0; i < lines.length; i++) { for (var i = 0; i < lines.length; i++) {
parts = lines[i].split(':') parts = lines[i].split(':')
if (parts[1]) { if (parts[1]) {
if (parts[0].indexOf('db') === 0) { if (parts[0].indexOf('db') === 0) {

View File

@@ -90,7 +90,7 @@ function execTransaction (multi) {
// Silently ignore this error. We'll receive the error for the exec as well // Silently ignore this error. We'll receive the error for the exec as well
const promises = [multi._client.internalSendCommand(new Command('multi', [])).catch(() => {})] const promises = [multi._client.internalSendCommand(new Command('multi', [])).catch(() => {})]
// Drain queue, callback will catch 'QUEUED' or error // Drain queue, callback will catch 'QUEUED' or error
for (let index = 0; index < len; index++) { for (var index = 0; index < len; index++) {
// The commands may not be shifted off, since they are needed in the result handler // The commands may not be shifted off, since they are needed in the result handler
promises.push(pipelineTransactionCommand(multi, multi._queue.get(index), index).catch((e) => e)) promises.push(pipelineTransactionCommand(multi, multi._queue.get(index), index).catch((e) => e))
} }
@@ -156,7 +156,7 @@ class Multi {
// Either undefined or an array. Fail hard if it's not an array // Either undefined or an array. Fail hard if it's not an array
if (args) { if (args) {
// Legacy support for passing in an array of arguments // Legacy support for passing in an array of arguments
for (let i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
const command = args[i][0] const command = args[i][0]
const tmpArgs = args[i].slice(1) const tmpArgs = args[i].slice(1)
if (Array.isArray(command)) { if (Array.isArray(command)) {

View File

@@ -62,7 +62,7 @@ function clone (obj) {
var copy var copy
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
copy = new Array(obj.length) copy = new Array(obj.length)
for (let i = 0; i < obj.length; i++) { for (var i = 0; i < obj.length; i++) {
copy[i] = clone(obj[i]) copy[i] = clone(obj[i])
} }
return copy return copy
@@ -70,7 +70,7 @@ function clone (obj) {
if (Object.prototype.toString.call(obj) === '[object Object]') { if (Object.prototype.toString.call(obj) === '[object Object]') {
copy = {} copy = {}
const elements = Object.keys(obj) const elements = Object.keys(obj)
for (let elem = elements.pop(); elem !== undefined; elem = elements.pop()) { for (var elem = elements.pop(); elem !== undefined; elem = elements.pop()) {
copy[elem] = clone(obj[elem]) copy[elem] = clone(obj[elem])
} }
return copy return copy