enable kvstore to bulk remove key/value pairs

RESOLVED FIXED in Firefox 68

Status

()

enhancement
P3
normal
RESOLVED FIXED
a month ago
27 days ago

People

(Reporter: myk, Assigned: nanj)

Tracking

unspecified
mozilla68
Points:
---

Firefox Tracking Flags

(firefox68 fixed)

Details

Attachments

(1 attachment)

(Reporter)

Description

a month ago

Bug 1522638 added bulk insert/clear to kvstore, which satisfies a number of use cases for transactions (bug 1499238), but there's one significant remaining case: a bulk change that removes multiple key/value pairs but doesn't clear them all.

With that addition, the "bulk change" feature set of kvstore should be sufficient to avoid the need for transactions and close bug 1499238 as wontfix.

One approach would be to add an nsIKeyValueDatabase.deleteMany() method that removes multiple pairs, which would satisfy the use case when pairs are only being removed.

But if pairs are also being inserted, and the consumer wants transactional semantics (either all pairs are inserted/removed or none of them are), then it'd be better to support both insertion and removal in the same single method call.

We could do that in nsIKeyValueDatabase.putMany() by allowing consumers to specify removal of a pair via an nsIKeyValuePair whose value is a void/empty variant.

Then nsIKeyValueDatabase.putMany({ "foo": "bar", "baz": null }) would insert the "foo": "bar" pair while removing a pair whose key is "baz" (if any).

(Assignee)

Comment 1

a month ago

Multiplexing deletion on putMany sounds a bit confusing to me, the consumer could also delete items inadvertently. FWIW, the current implementation treats 'null' as the invalid value thus will not finish the bulk insert.

Wonder if we can add a new API, say writeMany(), that can handle both put and delete with the argument proposed above.

We could still provide consumers with putMany and deleteMany on top of it for the better ergonomics.

(Assignee)

Updated

a month ago
Type: defect → enhancement
(Reporter)

Comment 2

a month ago

(In reply to Nan Jiang [:nanj] from comment #1)

Wonder if we can add a new API, say writeMany(), that can handle both put and delete with the argument proposed above.

We could still provide consumers with putMany and deleteMany on top of it for the better ergonomics.

That seems reasonable to me.

(Assignee)

Updated

a month ago
Assignee: nobody → najiang
Priority: -- → P3
(Assignee)

Comment 3

a month ago

This new API allows consumer to both put and delete in batch.

Comment 5

27 days ago
bugherder
Status: NEW → RESOLVED
Last Resolved: 27 days ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
You need to log in before you can comment on or make changes to this bug.