From c4194117a7896f7d968c745dbfaf7cb867b28d21 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 23 Jan 2020 14:33:00 -0500 Subject: [PATCH] ever so slightly faster direct message handler --- historyKeeper.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/historyKeeper.js b/historyKeeper.js index fe16a204c..2cb0f98ec 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -974,6 +974,12 @@ module.exports.create = function (cfg) { } }; + const directMessageCommands = { + GET_HISTORY: handleGetHistory, + GET_HISTORY_RANGE: handleGetHistoryRange, + GET_FULL_HISTORY: handleGetFullHistory, + }; + /* onDirectMessage * exported for use by the netflux-server * parses and handles all direct messages directed to the history keeper @@ -996,16 +1002,11 @@ module.exports.create = function (cfg) { // have to abort later (once we know the expiration time) if (checkExpired(ctx, parsed[1])) { return; } - if (parsed[0] === 'GET_HISTORY') { - return void handleGetHistory(ctx, seq, user, parsed); - } - if (parsed[0] === 'GET_HISTORY_RANGE') { - return void handleGetHistoryRange(ctx, seq, user, parsed); - } - if (parsed[0] === 'GET_FULL_HISTORY') { - return void handleGetFullHistory(ctx, seq, user, parsed); - } - return void handleRPC(ctx, seq, user, parsed); + // look up the appropriate command in the map of commands or fall back to RPC + var command = directMessageCommands[parsed[0]] || handleRPC; + + // run the command with the standard function signature + command(ctx, seq, user, parsed); }; return {