Closed Bug 1543836 Opened 5 years ago Closed 5 years ago

enable kvstore to bulk remove key/value pairs

Categories

(Toolkit :: Storage, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox68 --- fixed

People

(Reporter: myk, Assigned: nanj)

Details

Attachments

(1 file)

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).

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.

Type: defect → enhancement

(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: nobody → najiang
Priority: -- → P3

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

Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: