aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app/chat.ex
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-09-11 17:21:14 +0200
committerAlex Auvolat <alex@adnab.me>2018-09-11 17:21:14 +0200
commit9695231c327e052c5d5bc61197cc8222599fb91a (patch)
treec0d0f247269729658ad354a32475f34fa7268ed1 /shard/lib/app/chat.ex
parenta033c82a3c656a8f53feb60b5b149680771ac247 (diff)
downloadshard-9695231c327e052c5d5bc61197cc8222599fb91a.tar.gz
shard-9695231c327e052c5d5bc61197cc8222599fb91a.zip
Block store dependency management & caching (NOT TESTED)
Diffstat (limited to 'shard/lib/app/chat.ex')
-rw-r--r--shard/lib/app/chat.ex13
1 files changed, 12 insertions, 1 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index 471d8f7..4752dc6 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -160,6 +160,7 @@ defmodule SApp.Chat do
if mst2.root == new_root do
# This was the only message missing, we are happy!
state = %{state | mst: mst2}
+ GenServer.cast(state.block_store, {:set_roots, [mst2.root]})
msg_callback(state, msgitem)
state
else
@@ -186,9 +187,19 @@ defmodule SApp.Chat do
defp init_merge(state, new_root, source_peer) do
# TODO: make the merge asynchronous
+ prev_last = for {x, true} <- MST.last(state.mst, nil, 100), into: MapSet.new, do: x
+
mgmst = %{state.mst | root: new_root}
mgmst = put_in(mgmst.store.prefer_ask, [source_peer])
- mst = MST.merge(state.mst, mgmst, fn msgitem, true -> msg_callback(state, msgitem) end)
+ mst = MST.merge(state.mst, mgmst)
+
+ for {x, true} <- MST.last(mst, nil, 100) do
+ if not MapSet.member? prev_last, x do
+ msg_callback(state, x)
+ end
+ end
+
+ GenServer.cast(state.block_store, {:set_roots, [mst.root]})
%{state | mst: mst}
end