]> Entropealabs - cluster_kv.git/commitdiff
when no value exists check if it's list, and if it is, don't wrap it in onew
authorChristopher <chris@entropealabs.com>
Sun, 8 Mar 2020 04:19:36 +0000 (22:19 -0600)
committerChristopher <chris@entropealabs.com>
Sun, 8 Mar 2020 04:19:36 +0000 (22:19 -0600)
lib/cluster_kv.ex
lib/cluster_kv/db.ex

index 71689a60ee901fb04e6f676dcf8273cacedc1fb0..12aa55b6972a7ccf2918820952dc6d54fba419ec 100644 (file)
@@ -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])
index f334c47b7e16183c5a64edd9d95a3256f4fa78fa..4b963008e129fff76f8084609a6f1cb5b6008dc5 100644 (file)
@@ -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)