A peer-to-peer stack for code collaboration
Correctly order results when loading initial state
Thomas Scholtes233c6466967d
diff --git a/exe/Server.hs b/exe/Server.hsindex 1fd016e..26f373a 100644--- a/exe/Server.hs+++ b/exe/Server.hs@@ -113,7 +113,9 @@ loadState conn = dolet go acc x = eval x >>= \v -> pure (acc Seq.|> (x, v))let st = runIdentity $ runLang pureEnv $ foldM go mempty valscase st of- (Left err, _) -> panic $ show err+ (Left err, _) -> do+ logInfo "Failed to load machine" [("machine", name)]+ panic $ show err(Right pairs, st') -> dolet c = Chain { chainName = name, chainState = st'diff --git a/exe/Server/DB.hs b/exe/Server/DB.hsindex d62479b..6668bb9 100644--- a/exe/Server/DB.hs+++ b/exe/Server/DB.hs@@ -25,11 +25,14 @@ getSinceDB conn name id-- | Get all txs in all chains. Useful after a server restart.getAllDB :: Connection -> IO [(Text, [Value])]getAllDB conn = do- res :: [(Int, Text, Value)] <- query_ conn "SELECT id, chain, expr FROM txs"+ -- The @ORDER BY@ clauses are important, because+ -- * 'groupBy' only groups adjacent items in a list, and+ -- * inputs are evaluated in order+ res :: [(Int, Text, Value)] <- query_ conn "SELECT id, chain, expr FROM txs ORDER BY chain ASC, id ASC"+ -- TODO fold over the results and use a 'Map' to group chain inputslet grouped :: [[(Text, Value)]]grouped- = fmap (\(_, a, b) -> (a, b)) . sortOn (\(a,_,_) -> a)- <$> groupBy (\(_, l, _) (_, r, _) -> l == r) res+ = fmap (\(_, a, b) -> (a, b)) <$> groupBy (\(_, l, _) (_, r, _) -> l == r) respure [ (fst (head each), snd <$> each) | each <- grouped ]