Small refactoring

This commit is contained in:
Maxim Baz
2019-09-27 15:48:16 +02:00
parent a87623ff70
commit 3a2af64bc3

View File

@@ -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;