From f4a087d0eddfe2b71f488971e87e52e0629fafbb Mon Sep 17 00:00:00 2001 From: Kafji Date: Sun, 31 May 2020 10:46:24 +0700 Subject: [PATCH] Fix sync resource hog Hypothesis: On receiving onChanged event of browser.storage.sync, sync will try to _merge_ the container data and backup the merged data. One of the merging process is called reconcileSiteAssignments in which sync will remove assigned site form the delete site list. On each removal sync will tell assignManager, the one who hold container data locally, to remove it as well. In turn the assignManager will remove *and then* tell sync to backup the data. This causes the backup process in sync to be invoked multiple times, one from the sync process and one for each of removed assigned site list. To make matters worse, the backup from removal of assigned site list will run in parallel from each others. This might fixes #1691. --- src/js/background/assignManager.js | 4 ++-- src/js/background/sync.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index deee22a..a328610 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -84,13 +84,13 @@ window.assignManager = { return; }, - async remove(pageUrlorUrlKey) { + async remove(pageUrlorUrlKey, shouldSync = true) { const siteStoreKey = this.getSiteStoreKey(pageUrlorUrlKey); // When we remove an assignment we should clear all the exemptions this.removeExempted(pageUrlorUrlKey); await this.area.remove([siteStoreKey]); const syncEnabled = await this.getSyncEnabled(); - if (syncEnabled) await sync.storageArea.backup({siteStoreKey}); + if (shouldSync && syncEnabled) await sync.storageArea.backup({siteStoreKey}); return; }, diff --git a/src/js/background/sync.js b/src/js/background/sync.js index b34ea00..6dfb629 100644 --- a/src/js/background/sync.js +++ b/src/js/background/sync.js @@ -493,9 +493,9 @@ async function reconcileSiteAssignments() { await sync.storageArea.getDeletedSiteList(); for(const siteStoreKey of deletedSiteList) { if (Object.prototype.hasOwnProperty.call(assignedSitesLocal,siteStoreKey)) { - assignManager + await assignManager .storageArea - .remove(siteStoreKey); + .remove(siteStoreKey, false); } }