better handling of batch renames
Rather than wait a full second, which may be longer than needed, or too short to get all the rename events, we start a mode where we wait 1/10th of a second, and if there are Changes received, wait again. Basically we're back in batch mode when this happens.
This commit is contained in:
parent
c961d97604
commit
393340dc3b
1 changed files with 22 additions and 13 deletions
|
@ -80,22 +80,11 @@ waitChangeTime a = runEvery (Seconds 1) <~> do
|
||||||
changes <- getChanges
|
changes <- getChanges
|
||||||
-- See if now's a good time to commit.
|
-- See if now's a good time to commit.
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
debug ["got", show changes]
|
|
||||||
case (shouldCommit now changes, possiblyrename changes) of
|
case (shouldCommit now changes, possiblyrename changes) of
|
||||||
(True, False) -> a (changes, now)
|
(True, False) -> a (changes, now)
|
||||||
(True, True) -> do
|
(True, True) -> do
|
||||||
{- Wait for other, related changes to arrive.
|
morechanges <- getrelatedchanges changes
|
||||||
- If there are multiple RmChanges, this is
|
a (changes ++ morechanges, now)
|
||||||
- probably a directory rename, so wait a full
|
|
||||||
- second to get all the Changes involved. -}
|
|
||||||
liftIO $ if length (filter isRmChange changes) > 1
|
|
||||||
then threadDelaySeconds $ Seconds 1
|
|
||||||
else humanImperceptibleDelay
|
|
||||||
-- Don't block, but are there any new changes?
|
|
||||||
morechanges <- getAnyChanges
|
|
||||||
debug ["got more", show morechanges]
|
|
||||||
let allchanges = changes++morechanges
|
|
||||||
a (allchanges, now)
|
|
||||||
_ -> refill changes
|
_ -> refill changes
|
||||||
where
|
where
|
||||||
{- Did we perhaps only get one of the AddChange and RmChange pair
|
{- Did we perhaps only get one of the AddChange and RmChange pair
|
||||||
|
@ -107,6 +96,26 @@ waitChangeTime a = runEvery (Seconds 1) <~> do
|
||||||
renamepart (PendingAddChange _ _) = True
|
renamepart (PendingAddChange _ _) = True
|
||||||
renamepart c = isRmChange c
|
renamepart c = isRmChange c
|
||||||
|
|
||||||
|
{- Gets changes related to the passed changes, without blocking
|
||||||
|
- very long.
|
||||||
|
-
|
||||||
|
- If there are multiple RmChanges, this is probably a directory
|
||||||
|
- rename, in which case it may be necessary to wait longer to get
|
||||||
|
- all the Changes involved.
|
||||||
|
-}
|
||||||
|
getrelatedchanges oldchanges
|
||||||
|
| length (filter isRmChange oldchanges) > 1 =
|
||||||
|
concat <$> getbatchchanges []
|
||||||
|
| otherwise = do
|
||||||
|
liftIO humanImperceptibleDelay
|
||||||
|
getAnyChanges
|
||||||
|
getbatchchanges cs = do
|
||||||
|
liftIO $ threadDelay $ fromIntegral $ oneSecond `div` 10
|
||||||
|
cs' <- getAnyChanges
|
||||||
|
if null cs'
|
||||||
|
then return cs
|
||||||
|
else getbatchchanges (cs':cs)
|
||||||
|
|
||||||
isRmChange :: Change -> Bool
|
isRmChange :: Change -> Bool
|
||||||
isRmChange (Change { changeInfo = i }) | i == RmChange = True
|
isRmChange (Change { changeInfo = i }) | i == RmChange = True
|
||||||
isRmChange _ = False
|
isRmChange _ = False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue