summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-08-23 13:41:38 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-08-23 13:41:38 -0400
commitab8cb0598927414aa8eef0af6ea3da20aba9b78b (patch)
tree3edb85a590b87bf46853992866cabaac6c662969 /Assistant
parent546ba8b7e1cf6b99f38aa0619397463422837ce0 (diff)
scan cheapest remotes first
This way, we get transfers from cheapest remotes.
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/ScanRemotes.hs20
1 files 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