Commit ff7fa6237f1f342357995c32488f542c984583d9

Authored by Sergey Matvienko
1 parent ab5f1b5b

js-executor: zero check and code cleanup

... ... @@ -121,9 +121,9 @@ JsInvokeMessageProcessor.prototype.processInvokeRequest = function (requestId, r
121 121 logger.debug('[%s] Processing invoke request, scriptId: [%s]', requestId, scriptId);
122 122 this.executedScriptsCounter++;
123 123 if (this.executedScriptsCounter % statFrequency == 0) {
124   - var nowMs = performance.now();
125   - var msSinceLastStat = nowMs - this.lastStatTime;
126   - var requestsPerSec = statFrequency / msSinceLastStat * 1000; //msSinceLastStat can't be zero in the real world
  124 + const nowMs = performance.now();
  125 + const msSinceLastStat = nowMs - this.lastStatTime;
  126 + const requestsPerSec = msSinceLastStat == 0 ? statFrequency : statFrequency / msSinceLastStat * 1000;
127 127 this.lastStatTime = nowMs;
128 128 logger.info('STAT[%s]: requests [%s], took [%s]ms, request/s [%s]', this.executedScriptsCounter, statFrequency, msSinceLastStat, requestsPerSec);
129 129 }
... ... @@ -197,13 +197,13 @@ JsInvokeMessageProcessor.prototype.getOrCompileScript = function (scriptId, scri
197 197 var self = this;
198 198 return new Promise(function (resolve, reject) {
199 199 const script = self.scriptMap.get(scriptId);
200   - if (script !== undefined) {
  200 + if (script) {
201 201 resolve(script);
202 202 } else {
203 203 self.executor.compileScript(scriptBody).then(
204   - (script) => {
205   - self.cacheScript(scriptId, script);
206   - resolve(script);
  204 + (compiledScript) => {
  205 + self.cacheScript(scriptId, compiledScript);
  206 + resolve(compiledScript);
207 207 },
208 208 (err) => {
209 209 reject(err);
... ...