Skip to content

Commit

Permalink
git-remote-ipfs: Load LOBs map only once
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Jan 23, 2019
1 parent c779c18 commit 42294ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
25 changes: 17 additions & 8 deletions git-remote-ipfs/src/Network/IPFS/Git/RemoteHelper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,23 @@ processPush _ localRef remoteRef = do

processFetch :: Text -> RemoteHelper ProcessError ()
processFetch sha = do
repo <- Git.getGit
root <- asks envIpfsRoot
cid <- liftEitherRH . first CidError $ cidFromHexShaText sha
lobjs <- ipfs $ largeObjects root -- XXX: load lobjs only once
lck <- liftIO $ newMVar ()
go repo root lobjs lck cid
repo <- Git.getGit
root <- asks envIpfsRoot
cid <- liftEitherRH . first CidError $ cidFromHexShaText sha
lck <- liftIO $ newMVar ()
lobs <- do
env <- ask
(>>= either throwError pure)
. liftIO . modifyMVar (envLobs env) $ \case
Just ls -> pure (Just ls, Right ls)
Nothing ->
runRemoteHelper env (ipfs (largeObjects root)) >>= \case
Left e -> pure (Nothing, Left e)
Right ls -> pure (Just ls, Right ls)

go repo root lobs lck cid
where
go !repo !root !lobjs lck cid = do
go !repo !root !lobs lck cid = do
ref <- liftEitherRH . first CidError $ cidToRef @Git.SHA1 cid
have <-
-- Nb. mutex here as we might access the same packfile concurrently
Expand All @@ -223,7 +232,7 @@ processFetch sha = do
fmt ("fetch: Skipping " % fref % " (" % fcid % ")") ref cid
Nothing -> do
raw <- do
blk <- ipfs $ provideBlock lobjs cid
blk <- ipfs $ provideBlock lobs cid
case blk of
Just b -> pure b
Nothing -> ipfs $ getBlock cid
Expand Down
5 changes: 5 additions & 0 deletions git-remote-ipfs/src/Network/IPFS/Git/RemoteHelper/Trans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Network.IPFS.Git.RemoteHelper.Trans
, envOptions
, envClient
, envIpfsRoot
, envLobs

, RemoteHelper
, RemoteHelperT
Expand Down Expand Up @@ -40,13 +41,15 @@ module Network.IPFS.Git.RemoteHelper.Trans
where

import qualified Control.Concurrent.Async as Async
import Control.Concurrent.MVar (MVar, newMVar)
import Control.Concurrent.QSem
import Control.Exception.Safe
import qualified Control.Lens as Lens
import Control.Monad.Except
import Control.Monad.Reader
import qualified Data.Aeson.Lens as Lens
import Data.Bifunctor (first)
import Data.HashMap.Strict (HashMap)
import Data.IORef (IORef, newIORef, readIORef)
import Data.Maybe (fromMaybe)
import Data.Proxy (Proxy(..))
Expand Down Expand Up @@ -99,6 +102,7 @@ data Env = Env
, envGit :: Git SHA1
, envClient :: Servant.ClientEnv
, envIpfsRoot :: CID
, envLobs :: MVar (Maybe (HashMap CID CID))
}

class DisplayError a where
Expand Down Expand Up @@ -243,6 +247,7 @@ newEnv envLogger envOptions = do
envVerbosity <- newIORef 1
envDryRun <- newIORef False
envGit <- findRepo >>= openRepo
envLobs <- newMVar Nothing
ipfsBase <-
Servant.parseBaseUrl
=<< fromMaybe "http://localhost:5001" <$> lookupEnv "IPFS_API_URL"
Expand Down

0 comments on commit 42294ab

Please sign in to comment.