Skip to content

Commit 07eae00

Browse files
committed
Add entity count when loading dependencies
1 parent d95114b commit 07eae00

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ saveObject ::
686686
ObjectType ->
687687
ByteString ->
688688
Transaction ObjectId
689-
saveObject hh h t blob = do
689+
saveObject _hh h t blob = do
690690
execute
691691
[sql|
692692
INSERT INTO object (primary_hash_id, type_id, bytes)
@@ -695,11 +695,11 @@ saveObject hh h t blob = do
695695
|]
696696
oId <- expectObjectIdForPrimaryHashId h
697697
saveHashObject h oId 2 -- todo: remove this from here, and add it to other relevant places once there are v1 and v2 hashes
698-
rowsModified >>= \case
699-
0 -> pure ()
700-
_ -> do
701-
hash <- expectHash32 h
702-
tryMoveTempEntityDependents hh hash
698+
-- rowsModified >>= \case
699+
-- 0 -> pure ()
700+
-- _ -> do
701+
-- hash <- expectHash32 h
702+
-- tryMoveTempEntityDependents hh hash
703703
pure oId
704704

705705
expectObject :: SqliteExceptionReason e => ObjectId -> (ByteString -> Either e a) -> Transaction a
@@ -957,7 +957,7 @@ saveCausal ::
957957
BranchHashId ->
958958
[CausalHashId] ->
959959
Transaction ()
960-
saveCausal hh self value parents = do
960+
saveCausal _hh self value parents = do
961961
execute
962962
[sql|
963963
INSERT INTO causal (self_hash_id, value_hash_id)
@@ -973,13 +973,13 @@ saveCausal hh self value parents = do
973973
INSERT INTO causal_parent (causal_id, parent_id)
974974
VALUES (:self, :parent)
975975
|]
976-
flushCausalDependents hh self
976+
-- flushCausalDependents hh self
977977

978-
flushCausalDependents ::
978+
_flushCausalDependents ::
979979
HashHandle ->
980980
CausalHashId ->
981981
Transaction ()
982-
flushCausalDependents hh chId = do
982+
_flushCausalDependents hh chId = do
983983
hash <- expectHash32 (unCausalHashId chId)
984984
tryMoveTempEntityDependents hh hash
985985

unison-cli/src/Unison/Share/SyncV2.hs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Data.Conduit.Zlib qualified as C
2626
import Data.Graph qualified as Graph
2727
import Data.Map qualified as Map
2828
import Data.Set qualified as Set
29+
import Data.Text.IO qualified as Text
2930
import Servant.Conduit ()
3031
import System.Console.Regions qualified as Console.Regions
3132
import U.Codebase.HashTags (CausalHash)
@@ -217,7 +218,9 @@ withEntityStream ::
217218
(Int -> Stream () SyncV2.DownloadEntitiesChunk -> m r) ->
218219
m r
219220
withEntityStream conn rootHash mayBranchRef callback = do
220-
entities <- liftIO $ Sqlite.runTransaction conn (depsForCausal rootHash)
221+
entities <- liftIO $ withEntityLoadingCallback $ \counter -> do
222+
Sqlite.runTransaction conn (depsForCausal rootHash counter)
223+
liftIO $ Text.hPutStrLn IO.stderr $ "Finished loading entities, writing sync-file."
221224
let totalEntities = fromIntegral $ Map.size entities
222225
let initialChunk =
223226
SyncV2.InitialC
@@ -256,8 +259,8 @@ syncToFile codebase rootHash mayBranchRef destFilePath = do
256259
C.runConduit $ stream C..| countC C..| C.map (BL.toStrict . CBOR.serialise) C..| C.transPipe liftIO C.gzip C..| C.sinkFile destFilePath
257260

258261
-- | Collect all dependencies of a given causal hash.
259-
depsForCausal :: CausalHash -> Sqlite.Transaction (Map Hash32 (Sync.Entity Text Hash32 Hash32))
260-
depsForCausal causalHash = do
262+
depsForCausal :: CausalHash -> (Int -> IO ()) -> Sqlite.Transaction (Map Hash32 (Sync.Entity Text Hash32 Hash32))
263+
depsForCausal causalHash counter = do
261264
flip execStateT mempty $ expandEntities (causalHashToHash32 causalHash)
262265
where
263266
expandEntities :: Hash32 -> ((StateT (Map Hash32 (Sync.Entity Text Hash32 Hash32)) Sqlite.Transaction)) ()
@@ -267,6 +270,7 @@ depsForCausal causalHash = do
267270
False -> do
268271
entity <- lift $ Sync.expectEntity hash32
269272
modify (Map.insert hash32 entity)
273+
lift . Sqlite.unsafeIO $ counter 1
270274
traverseOf_ Sync.entityHashes_ expandEntities entity
271275

272276
-- | Gets the framed chunks from a NetString framed stream.
@@ -374,3 +378,18 @@ withStreamProgressCallback total action = do
374378
toIO $ action $ C.awaitForever \i -> do
375379
liftIO $ IO.atomically (IO.modifyTVar' entitiesDownloadedVar (+ 1))
376380
C.yield i
381+
382+
withEntityLoadingCallback :: (MonadUnliftIO m) => ((Int -> m ()) -> m a) -> m a
383+
withEntityLoadingCallback action = do
384+
counterVar <- IO.newTVarIO (0 :: Int)
385+
IO.withRunInIO \toIO -> do
386+
Console.Regions.displayConsoleRegions do
387+
Console.Regions.withConsoleRegion Console.Regions.Linear \region -> do
388+
Console.Regions.setConsoleRegion region do
389+
processed <- IO.readTVar counterVar
390+
pure $
391+
"\n Loading "
392+
<> tShow processed
393+
<> " entities...\n\n"
394+
toIO $ action $ \i -> do
395+
liftIO $ IO.atomically (IO.modifyTVar' counterVar (+ i))

0 commit comments

Comments
 (0)