Skip to content

Proposal: Retrieving, deleting storage items using a filter.  #505

@polywock

Description

@polywock

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 prefix flag: is using StorageArea.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 use StorageArea.remove to delete them.

Why it's Needed (Organization)

This proposal allows extension developers to group, retrieve, and delete a collection of related keys.

browser.storage.local.get(['content/a', 'content/b', 'content/c', 'content/d', 'content/e', 'content/f', ...])

// becomes 
browser.storage.local.get(['content/*'], true) 

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.

type StorageFilter = Glob[] | FullStorageFilter

interface FullStorageFilter {
    matches: Glob[],
    excludeMatches: Glob[] 
}

Usage if new methods are introduced.

browser.storage.local.getUsingFilter(['flag:*'])

browser.storage.local.removeUsingFilter(['flag:*'])

Usage if existing methods are used.

The second parameter true indicates we're using filters.

browser.storage.local.get(['flag:*'], true)

browser.storage.local.remove(['flag:*'], true)

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportive: chromeSupportive from Chrometopic: storageIssues related to persisting data. Topics include browser.storage, web storage, and new APIs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions