serokell / coffer

Multi-backend password store with multiple frontends
4 stars 2 forks source link

Avoid creating many connection managers #25

Open dcastro opened 2 years ago

dcastro commented 2 years ago

In runVaultIO, we're creating a new connection manager on every BackendEffect action:

    env <-
      case url of
        (BaseUrl Http _ _ _) -> do
          manager <- embed $ newManager defaultManagerSettings
          pure $ mkClientEnv manager url
        (BaseUrl Https _ _ _) -> do
          manager <- embed $ newManager tlsManagerSettings
          pure $ mkClientEnv manager url

This can be observed by adding a trace statement:

          manager <- embed $ do
            traceM "Creating manager"
            newManager defaultManagerSettings

And then running coffer view / (after creating a few entries):

$ cabal run exe:coffer -- view /

"Creating manager"
"Creating manager"
"Creating manager"
"Creating manager"
"Creating manager"
"Creating manager"
"Creating manager"
"Creating manager"
/
  test/
    ...

We should refactor this so only 1 connection manager is created.