From: Christopher Date: Sun, 8 Mar 2020 04:19:36 +0000 (-0600) Subject: when no value exists check if it's list, and if it is, don't wrap it in onew X-Git-Url: http://git.entropealabs.com/?a=commitdiff_plain;h=c2df59aa3a065aa6c8bea70be3d5b88ee953eeba;p=cluster_kv.git when no value exists check if it's list, and if it is, don't wrap it in onew --- diff --git a/lib/cluster_kv.ex b/lib/cluster_kv.ex index 71689a6..12aa55b 100644 --- a/lib/cluster_kv.ex +++ b/lib/cluster_kv.ex @@ -35,7 +35,7 @@ defmodule ClusterKV do {Ring, [{:local, ring}, ring_data, []]} ] - Supervisor.init(children, strategy: :one_for_one, max_restarts: 5, max_seconds: 10) + Supervisor.init(children, strategy: :rest_for_one, max_restarts: 5, max_seconds: 10) end def db_name(name), do: Module.concat([name, DB]) diff --git a/lib/cluster_kv/db.ex b/lib/cluster_kv/db.ex index f334c47..4b96300 100644 --- a/lib/cluster_kv/db.ex +++ b/lib/cluster_kv/db.ex @@ -31,7 +31,7 @@ defmodule ClusterKV.DB do GenServer.cast(name, {:upsert, key, value, fun}) end - def batch(name, batch, chunk \\ 100, fun \\ &{elem(&1, 0), Enum.uniq([&2 | elem(&1, 1)])}) do + def batch(name, batch, chunk \\ 100, fun \\ &{elem(&1, 0), &2}) do GenServer.cast(name, {:batch, batch, chunk, fun}) end @@ -100,7 +100,13 @@ defmodule ClusterKV.DB do defp do_upsert(db, key, value, fun) do case :ets.lookup(db, key) do [] -> - :ets.insert(db, {key, [value]}) + v = + case value do + val when is_list(val) -> val + val -> [val] + end + + :ets.insert(db, {key, v}) [{_, val} = old] when is_list(val) -> new = fun.(old, value)