From 3a2af64bc3b55c771bfd30c5ee39a149c3fac0ad Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Fri, 27 Sep 2019 15:48:16 +0200 Subject: [PATCH] Small refactoring --- src/background.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/background.js b/src/background.js index d9302d7..3d214b5 100644 --- a/src/background.js +++ b/src/background.js @@ -112,6 +112,10 @@ chrome.runtime.onInstalled.addListener(onExtensionInstalled); * @return void */ async function updateMatchingPasswordsCount(tabId, forceRefresh = false) { + if (badgeCache.isRefreshing) { + return; + } + try { if (forceRefresh || Date.now() > badgeCache.expires) { badgeCache.isRefreshing = true; @@ -122,18 +126,15 @@ async function updateMatchingPasswordsCount(tabId, forceRefresh = false) { throw new Error(JSON.stringify(response)); } + const CACHE_TTL_MS = 60 * 1000; badgeCache = { files: response.data.files, settings: settings, - expires: Date.now() + 60 * 1000, + expires: Date.now() + CACHE_TTL_MS, isRefreshing: false }; } - if (badgeCache.isRefreshing) { - return; - } - try { const tab = await chrome.tabs.get(tabId); badgeCache.settings.host = new URL(tab.url).hostname;