mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-23 01:11:56 +01:00
Prevent concurrent Hoogle queries #172
This commit is contained in:
parent
4b953f8585
commit
c5f16f2faa
@ -146,6 +146,7 @@ makeFoundation useEcho conf = do
|
|||||||
, updateAction = getLatestMatcher manager
|
, updateAction = getLatestMatcher manager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hoogleLock <- newMVar ()
|
||||||
let logger = Yesod.Core.Types.Logger loggerSet' getter
|
let logger = Yesod.Core.Types.Logger loggerSet' getter
|
||||||
foundation = App
|
foundation = App
|
||||||
{ settings = conf
|
{ settings = conf
|
||||||
@ -156,6 +157,7 @@ makeFoundation useEcho conf = do
|
|||||||
, websiteContent = websiteContent'
|
, websiteContent = websiteContent'
|
||||||
, stackageDatabase = stackageDatabase'
|
, stackageDatabase = stackageDatabase'
|
||||||
, latestStackMatcher = latestStackMatcher'
|
, latestStackMatcher = latestStackMatcher'
|
||||||
|
, appHoogleLock = hoogleLock
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundation
|
return foundation
|
||||||
|
|||||||
@ -30,6 +30,9 @@ data App = App
|
|||||||
, stackageDatabase :: IO StackageDatabase
|
, stackageDatabase :: IO StackageDatabase
|
||||||
, latestStackMatcher :: IO (Text -> Maybe Text)
|
, latestStackMatcher :: IO (Text -> Maybe Text)
|
||||||
-- ^ Give a pattern, get a URL
|
-- ^ Give a pattern, get a URL
|
||||||
|
, appHoogleLock :: MVar ()
|
||||||
|
-- ^ Avoid concurrent Hoogle queries, see
|
||||||
|
-- https://github.com/fpco/stackage-server/issues/172
|
||||||
}
|
}
|
||||||
|
|
||||||
instance HasGenIO App where
|
instance HasGenIO App where
|
||||||
|
|||||||
@ -37,8 +37,11 @@ getHoogleR name = do
|
|||||||
Just x -> return $ liftIO $ Hoogle.loadDatabase x
|
Just x -> return $ liftIO $ Hoogle.loadDatabase x
|
||||||
Nothing -> hoogleDatabaseNotAvailableFor name
|
Nothing -> hoogleDatabaseNotAvailableFor name
|
||||||
|
|
||||||
|
-- Avoid concurrent Hoogle queries, see
|
||||||
|
-- https://github.com/fpco/stackage-server/issues/172
|
||||||
|
lock <- appHoogleLock <$> getYesod
|
||||||
mresults <- case mquery of
|
mresults <- case mquery of
|
||||||
Just query -> runHoogleQuery heDatabase HoogleQueryInput
|
Just query -> withMVar lock $ const $ runHoogleQuery heDatabase HoogleQueryInput
|
||||||
{ hqiQueryInput = query
|
{ hqiQueryInput = query
|
||||||
, hqiExactSearch = if exact then Just query else Nothing
|
, hqiExactSearch = if exact then Just query else Nothing
|
||||||
, hqiLimitTo = count'
|
, hqiLimitTo = count'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user