replikativ / konserve

A clojuresque key-value/document store protocol with core.async.
Eclipse Public License 1.0
299 stars 25 forks source link

Support multiple keys in `dissoc` #26

Open purrgrammer opened 5 years ago

purrgrammer commented 5 years ago

The key-value protocol's dissoc method supports removing one key at a time. Clojure's dissoc supports removing several keys at once:

(dissoc {:a 1 :b 2 :c 3} :c :b)
;;=> {:a 1}

Would it make sense for dissoc in Konserve to accept multiple keys as well?

Note that deletions of multiple keys could be batched for a performance gain in the underlying backend implementations. This is a breaking API change so I figured out I should I ask before submitting a patch.

I've also noticed that due to the insertion being based on assoc-in there is no way to perform batched updates. We could also consider adding a variant of assoc-in (or assoc) that allows for batched inserts, which projects like Datahike could ultimately benefit from.

whilo commented 5 years ago

That sounds reasonable to me. How would you do the batching? It would be a breaking change if the channel would close before the IO operations have succeeded. Operations can run in parallel as long as:

  1. Any arising error propagates as a value in the resulting channel.
  2. The whole operation does not succeed before all batched operations have succeeded.

Note that the user of the konserve API can still decide not to wait for the channel to close. Writing a patch with a bit of core.async foo, e.g. mapping over all keys to create channels and then go-looping over the lazy seq of channels to aggregate the result (any error), should do the trick I think.