From 7df34aa7a40be0d7b759ea3ef42cedf9f25f32b2 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 10 Jan 2023 21:36:03 +0100 Subject: commands: add a nice terminal progress bar when building the cache One issue remaining is that writing the cache takes significant time, but I don't know how to reflect that nicely to the user. --- entity/dag/entity.go | 10 +++++++++- entity/streamed.go | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'entity') diff --git a/entity/dag/entity.go b/entity/dag/entity.go index 2028e1b4..f8dbd53d 100644 --- a/entity/dag/entity.go +++ b/entity/dag/entity.go @@ -314,6 +314,9 @@ func ReadAll[EntityT entity.Interface](def Definition, wrapper func(e *Entity) E return } + total := int64(len(refs)) + current := int64(1) + for _, ref := range refs { e, err := read[EntityT](def, wrapper, repo, resolvers, ref) @@ -322,7 +325,12 @@ func ReadAll[EntityT entity.Interface](def Definition, wrapper func(e *Entity) E return } - out <- entity.StreamedEntity[EntityT]{Entity: e} + out <- entity.StreamedEntity[EntityT]{ + Entity: e, + CurrentEntity: current, + TotalEntities: total, + } + current++ } }() diff --git a/entity/streamed.go b/entity/streamed.go index 789224a3..33124ef0 100644 --- a/entity/streamed.go +++ b/entity/streamed.go @@ -1,6 +1,11 @@ package entity type StreamedEntity[EntityT Interface] struct { - Entity EntityT Err error + Entity EntityT + + // CurrentEntity is the index of the current entity being streamed, to express progress. + CurrentEntity int64 + // TotalEntities is the total count of expected entities, if known. + TotalEntities int64 } -- cgit