summaryrefslogtreecommitdiff
path: root/src/common/Storage.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Storage.js')
-rw-r--r--src/common/Storage.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/common/Storage.js b/src/common/Storage.js
index c534bfb..78c481b 100644
--- a/src/common/Storage.js
+++ b/src/common/Storage.js
@@ -71,12 +71,14 @@ var Storage = (() => {
// Firefox Sync's max object BYTEs size is 16384, Chrome's 8192.
// Rather than mesuring actual bytes, we play it safe by halving then
// lowest to cope with escapes / multibyte characters.
+ let removeKeys = [];
for (let k of Object.keys(keys)) {
let s = JSON.stringify(keys[k]);
+ let chunksCountKey = chunksKey(k);
+ let oldCount = await browser.storage.sync.get(chunksCountKey)[chunksCountKey] || 0;
+ let count;
if (s.length > MAX_ITEM_SIZE) {
- let count = Math.ceil(s.length / MAX_ITEM_SIZE);
- let chunksCountKey = chunksKey(k);
- let oldCount = await browser.storage.sync.get(chunksCountKey);
+ count = Math.ceil(s.length / MAX_ITEM_SIZE);
let chunks = {
[chunksCountKey]: count
};
@@ -85,15 +87,17 @@ var Storage = (() => {
}
await browser.storage.sync.set(chunks);
keys[k] = "[CHUNKED]";
- if (oldCount-- > count) {
- let oldChunks = [];
- do {
- oldChunks.push(`${k}${oldCount}`);
- } while(oldCount-- > count);
- await browser.storage.sync.remove(oldChunks);
- }
+ } else {
+ count = 0;
+ removeKeys.push(chunksCountKey);
+ }
+ if (oldCount-- > count) {
+ do {
+ removeKeys.push(`${k}${oldCount}`);
+ } while(oldCount-- > count);
}
}
+ await browser.storage.sync.remove(removeKeys);
}
}