From aebcabf77d8333e9a4ec66c1818429022d0d9f48 Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 6 Sep 2017 23:16:54 -0400 Subject: [PATCH] using global one setInterval instead of scheduling setTimeout after each encryption operation (there can be many of them) --- static/js/encryption.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/static/js/encryption.js b/static/js/encryption.js index 59a886f4f..b97107ee6 100644 --- a/static/js/encryption.js +++ b/static/js/encryption.js @@ -111,26 +111,26 @@ $("#encryptionPasswordForm").submit(function() { return false; }); -function getAes() { - globalLastEncryptionOperationDate = new Date(); +setInterval(function() { + if (globalLastEncryptionOperationDate !== null && new Date().getTime() - globalLastEncryptionOperationDate.getTime() > globalEncryptionKeyTimeToLive) { + globalEncryptionKey = null; - setTimeout(function() { - if (new Date().getTime() - globalLastEncryptionOperationDate.getTime() > globalEncryptionKeyTimeToLive) { - globalEncryptionKey = null; + if (globalNote.detail.encryption > 0) { + loadNote(globalNote.detail.note_id); - if (globalNote.detail.encryption > 0) { - loadNote(globalNote.detail.note_id); + for (const noteId of globalAllNoteIds) { + const note = getNodeByKey(noteId); - for (const noteId of globalAllNoteIds) { - const note = getNodeByKey(noteId); - - if (note.data.encryption > 0) { - note.setTitle("[encrypted]"); - } + if (note.data.encryption > 0) { + note.setTitle("[encrypted]"); } } } - }, globalEncryptionKeyTimeToLive + 1000); + } +}, 5000); + +function getAes() { + globalLastEncryptionOperationDate = new Date(); return new aesjs.ModeOfOperation.ctr(globalEncryptionKey, new aesjs.Counter(5)); }