-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Retrieving, deleting storage items using a filter. #505
Comments
I'd rather keep the existing API and just pass a regex. Alternatively globs would be flexible and match existing webext browser.storage.local.get(/^flag:/)
browser.storage.local.get({match: 'flag:*'}) |
browser.storage.local.get(/^flag:/) Looks great, but the other one isn't backward compatible. Whichever format it ends up being, it should probably be consistent with proposal #475. |
Ah you're right, I forgot objects are used to provide defaults. |
The simplest solution would be to add However, chrome.storage API was never designed to be performant and flexible, so maybe a better solution would be to add
JS RegExp won't work in Chrome as it only supports RE2 syntax inside the browser processes for the sake of guaranteed performance due to the absence of backtracking. It may be worse in other browsers, e.g. Safari supports a very limited/nonstandard subset of RE for a similar reason in declarativeNetRequest.
would work for most cases I guess, but it's too limited, so ideally it should be extended with ranges like |
There is little appetite for the proposed API, but the browser vendors are willing to consider adding a new method to retrieve all known storage keys (return value: a list of strings). This would enable you to implement the filtering yourself, and then pass the array of keys to get/remove (or a new object with What are your thoughts on this counter-proposal? |
A dumb getAllKeys() is the bare minimum, but it'll still be wasteful when there are many keys, so it's best if we can specify lower/upper bounds for the keys just like IndexedDB's getAllKeys or something similar. |
@Rob--W I'm supportive, but ideally both should be implemented. Some advantages for a filter based approach.
|
@polywock, to clarify - if only |
I'd definitely use it in my module to only fetch items that belong to it ("starts with cache:") I think it's a fair compromise, if the filter for .get() isn't accepted. However I wonder what browsers gain from this dual API since it feels like it halves the performance (two lookups) I also have another module that populates/autosaves the options page into the storage, given a schema. It currently uses a single key and the options are stored as a single object. With this API, I would be able to store one item per field, without losing the core features (like the ability to migrate keys that are no longer in the schema) |
Simplicity. They want to keep this API simple. A getAllKeys method was always a necessity though, so it's a good compromise for them, whereas we'll still get the benefit of not reading huge values. |
@oliverdunk It's not my preferred method, but getKeys() will be very useful. |
BackgroundBecause The original intent of #475 was to support multiple space. Considering that browsers may not support this change, a compromise was made. If browsers supported multiple spaces, this proposal #505 would not exist. So the proposal #505 itself is a product of compromise. Now, |
Since I have long since edited my 475 proposal. For those who don't know, in 475 I had two proposals. The primary proposal was to support buckets/spaces for the storage API, and allow retrieving, deleting from a specific bucket, or listening to changes on a specific bucket. From the feedback, I switched focus to the secondary proposal (StorageArea.onChanged supporting a filter). I wouldn't say this was a compromise since I included the secondary proposal alongside the main proposal. I prefer the secondary proposal as of today, especially if paired with #505 (or even the counter-proposal, getKeys). All things considered, I'm still satisfied a counter-proposal was accepted. It won't be as efficient as the original, but it will still allow for getting filtered keys more efficiently. It would be interesting to do benchmarks to figure out at what point it's better to use In addition, if using getKeys() to filter becomes common, the browsers might later implement a dedicated function to optimize it. |
My guess is that it has limited use for That leaves In any case, the most common usage would probably look something like this: const cache = await chrome.storage.local.get(await chrome.storage.local.getKeys('cache:*')) await chrome.storage.local.remove(await chrome.storage.local.getKeys('cache:*')) |
@fregante PS: I didn't say |
I had a chance to speak to the engineering team about this. On the Chrome side, we're supportive of a |
This is already implemented: chrome.storage.XXXX. |
Do you mean |
Closing in favor of #601. |
Why it's Needed (Efficiency)
I regularly need to use storage keys that involve dynamic elements like
flag:[tabId]
. The only way to get all keys starting with the prefixflag:
is usingStorageArea.get()
to get all the storage items and then to filter.This isn't very efficient. The storage areas support 10MB of data and even more with the
unlimitedStorage
permission. That's potentially a huge amount of storage data that needs to be serialized and sent over. There's also a special concern when using the Sync storage area.To delete all keys with prefix
flags:
is even worse as it requires a three step process. Get all storage items, filter for keys you want to delete, and useStorageArea.remove
to delete them.Why it's Needed (Organization)
This proposal allows extension developers to group, retrieve, and delete a collection of related keys.
Proposal
A way to retrieve and delete storage items using a filter. The filter can be a list of globs or an object. Preferably the same filter should be used for this proposal and #475.
Usage if new methods are introduced.
Usage if existing methods are used.
The second parameter true indicates we're using filters.
The text was updated successfully, but these errors were encountered: