use global cache adding function

This commit is contained in:
Trolli Schmittlauch 2020-05-26 08:55:44 +02:00
parent e3bfa26ddb
commit ad1465c5fe

View file

@ -203,14 +203,14 @@ queryIdLookupLoop cacheSnapshot ns targetID = do
now <- getPOSIXTime now <- getPOSIXTime
newLCache <- foldM (\oldCache resp -> do newLCache <- foldM (\oldCache resp -> do
let entriesToInsert = case queryResult <$> payload resp of let entriesToInsert = case queryResult <$> payload resp of
Just (FOUND result1) -> [addCacheEntryPure now (RemoteCacheEntry result1 now)] Just (FOUND result1) -> [RemoteCacheEntry result1 now]
Just (FORWARD resultset) -> addCacheEntryPure now <$> Set.elems resultset Just (FORWARD resultset) -> Set.elems resultset
_ -> [] _ -> []
-- forward entries to global cache -- forward entries to global cache
forM_ entriesToInsert $ \entry -> atomically $ writeTQueue (cacheWriteQueue ns) entry queueAddEntries entriesToInsert ns
-- insert entries into local cache copy -- insert entries into local cache copy
pure $ foldl' ( pure $ foldr' (
\oldLCache insertFunc -> insertFunc oldLCache addCacheEntryPure now
) oldCache entriesToInsert ) oldCache entriesToInsert
) cacheSnapshot responses ) cacheSnapshot responses
@ -283,7 +283,7 @@ sendRequestTo timeoutMillis numAttempts msgIncomplete sock = do
-- | enqueue a list of RemoteCacheEntries to be added to the global NodeCache -- | enqueue a list of RemoteCacheEntries to be added to the global NodeCache
queueAddEntries :: [RemoteCacheEntry] queueAddEntries :: Foldable c => c RemoteCacheEntry
-> LocalNodeState -> LocalNodeState
-> IO () -> IO ()
queueAddEntries entries ns = do queueAddEntries entries ns = do