diff options
author | hackademix | 2019-10-23 00:08:05 +0200 |
---|---|---|
committer | hackademix | 2019-10-25 23:19:48 +0100 |
commit | 7f4c3450fdc6895bf36eeba9c3184a0814275a21 (patch) | |
tree | 7f0eb1b4837eee73879e7be106cd1a6b3ee4dab6 /src/common/Storage.js | |
parent | d196982cd5c7315d3825456223fee158bf01766c (diff) | |
download | noscript-7f4c3450fdc6895bf36eeba9c3184a0814275a21.tar.gz noscript-7f4c3450fdc6895bf36eeba9c3184a0814275a21.tar.xz noscript-7f4c3450fdc6895bf36eeba9c3184a0814275a21.zip |
Fixed bug in chunked storage causing shrunk items not to be retrieved correctly.
Diffstat (limited to 'src/common/Storage.js')
-rw-r--r-- | src/common/Storage.js | 24 |
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); } } |