From ad1465c5fe50af1b9adf3db94b3f9a1c3725889d Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Tue, 26 May 2020 08:55:44 +0200 Subject: [PATCH] use global cache adding function --- src/Hash2Pub/DHTProtocol.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Hash2Pub/DHTProtocol.hs b/src/Hash2Pub/DHTProtocol.hs index 7b07785..147fecc 100644 --- a/src/Hash2Pub/DHTProtocol.hs +++ b/src/Hash2Pub/DHTProtocol.hs @@ -203,14 +203,14 @@ queryIdLookupLoop cacheSnapshot ns targetID = do now <- getPOSIXTime newLCache <- foldM (\oldCache resp -> do let entriesToInsert = case queryResult <$> payload resp of - Just (FOUND result1) -> [addCacheEntryPure now (RemoteCacheEntry result1 now)] - Just (FORWARD resultset) -> addCacheEntryPure now <$> Set.elems resultset + Just (FOUND result1) -> [RemoteCacheEntry result1 now] + Just (FORWARD resultset) -> Set.elems resultset _ -> [] -- forward entries to global cache - forM_ entriesToInsert $ \entry -> atomically $ writeTQueue (cacheWriteQueue ns) entry + queueAddEntries entriesToInsert ns -- insert entries into local cache copy - pure $ foldl' ( - \oldLCache insertFunc -> insertFunc oldLCache + pure $ foldr' ( + addCacheEntryPure now ) oldCache entriesToInsert ) cacheSnapshot responses @@ -283,7 +283,7 @@ sendRequestTo timeoutMillis numAttempts msgIncomplete sock = do -- | enqueue a list of RemoteCacheEntries to be added to the global NodeCache -queueAddEntries :: [RemoteCacheEntry] +queueAddEntries :: Foldable c => c RemoteCacheEntry -> LocalNodeState -> IO () queueAddEntries entries ns = do