From ab8cb0598927414aa8eef0af6ea3da20aba9b78b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 23 Aug 2012 13:41:38 -0400 Subject: scan cheapest remotes first This way, we get transfers from cheapest remotes. --- Assistant/ScanRemotes.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Assistant/ScanRemotes.hs b/Assistant/ScanRemotes.hs index 2362bd9b4..524dc200b 100644 --- a/Assistant/ScanRemotes.hs +++ b/Assistant/ScanRemotes.hs @@ -8,13 +8,15 @@ module Assistant.ScanRemotes where import Common.Annex -import Data.Function +import qualified Types.Remote as Remote +import Data.Function import Control.Concurrent.STM -import Data.Time.Clock import qualified Data.Map as M -type ScanRemoteMap = TMVar (M.Map Remote UTCTime) +type Priority = Int + +type ScanRemoteMap = TMVar (M.Map Remote Priority) {- The TMVar starts empty, and is left empty when there are no remotes - to scan. -} @@ -22,7 +24,7 @@ newScanRemoteMap :: IO ScanRemoteMap newScanRemoteMap = atomically newEmptyTMVar {- Blocks until there is a remote that needs to be scanned. - - Processes remotes added most recently first. -} + - Processes higher priority remotes first. -} getScanRemote :: ScanRemoteMap -> IO Remote getScanRemote v = atomically $ do m <- takeTMVar v @@ -37,9 +39,7 @@ getScanRemote v = atomically $ do {- Adds new remotes that need scanning to the map. -} addScanRemotes :: ScanRemoteMap -> [Remote] -> IO () -addScanRemotes _ [] = return () -addScanRemotes v rs = do - now <- getCurrentTime - atomically $ do - m <- fromMaybe M.empty <$> tryTakeTMVar v - putTMVar v $ foldr (`M.insert` now) m rs +addScanRemotes _ [] = noop +addScanRemotes v rs = atomically $ do + m <- fromMaybe M.empty <$> tryTakeTMVar v + putTMVar v $ M.union m $ M.fromList $ map (\r -> (r, Remote.cost r)) rs -- cgit v1.2.3