[temp file] simplify worker cleanup, add comments to large object functions

parent 0e65a7b3
Pipeline #7402 passed with stages
in 122 minutes and 47 seconds
......@@ -235,10 +235,7 @@ performAction env _state bm = do
-- TODO CES.filnally
$(logLocM) DEBUG "[performAction] add to corpus with temporary file"
CES.finally (addToCorpusWithTempFile _actf_user _actf_cid _actf_args jh)
(do
let oId = _wtf_file_oid _actf_args
$(logLocM) DEBUG $ "[performAction] removing large object: " <> show oId
removeLargeObject oId)
(removeLargeObject $ _wtf_file_oid _actf_args)
-- | Perform external API search query and index documents in corpus
AddCorpusWithQuery { .. } -> runWorkerMonad env $ do
......
......@@ -278,6 +278,12 @@ createDBIfNotExists connStr dbName = do
-- PostgreSQL Large Object functionality
-- https://www.postgresql.org/docs/17/largeobjects.html
-- NOTE: During development of this feature, I had problems (in tests)
-- with a hanging transaction. After debugging, it turned out this
-- was, for some reason, conflicting with our `logLocM` (though I'm no
-- sure why). Please be careful when adding debug info to large
-- objects and if you do, make sure the tests run.
createLargeObject :: BS.ByteString -> DBCmd err PSQL.Oid
createLargeObject bs = mkCmd $ \c -> PGS.withTransaction c $ do
oId <- PSQL.loCreat c
......@@ -286,6 +292,8 @@ createLargeObject bs = mkCmd $ \c -> PGS.withTransaction c $ do
PSQL.loClose c loFd
pure oId
-- | Read a large object directly, given an oid. We read it in a
-- single transaction, looping by given chunk size
readLargeObject :: PSQL.Oid -> DBCmd err BS.ByteString
readLargeObject oId = mkCmd $ \c -> PGS.withTransaction c $ do
loFd <- PSQL.loOpen c oId PSQL.ReadMode
......@@ -303,6 +311,9 @@ readLargeObject oId = mkCmd $ \c -> PGS.withTransaction c $ do
PSQL.loClose c loFd
pure s
-- | Read large object by exporting it to a temporary file, then
-- reading that file. The difference from 'readLargeObject' is that we
-- have only 1 call inside a transaction
readLargeObjectViaTempFile :: (CES.MonadMask m, IsDBCmd env err m)
=> PSQL.Oid -> m BS.ByteString
readLargeObjectViaTempFile oId = do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment