Skip to content

Commit

Permalink
Merge branch 'feat/index-analyze-command' of github.com:algolia/cli i…
Browse files Browse the repository at this point in the history
…nto feat/index-analyze-command
  • Loading branch information
clemfromspace committed Dec 6, 2023
2 parents dc8f536 + 85aa6ed commit f7822e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Stats struct {
}

// ComputeStats computes the stats for the given index.
func ComputeStats(i iterator.Iterator, s search.Settings, limit int, only string) (*Stats, error) {
func ComputeStats(i iterator.Iterator, s search.Settings, limit int, only string, counter chan int) (*Stats, error) {
settingsMap := settingsAsMap(s)
stats := &Stats{
Attributes: make(map[string]*AttributeStats),
Expand All @@ -72,6 +72,7 @@ func ComputeStats(i iterator.Iterator, s search.Settings, limit int, only string
}

stats.TotalRecords++
counter <- 1
stats = computeObjectStats(stats, "", object, only)
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/cmd/indices/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,18 @@ func runAnalyzeCmd(opts *StatsOptions) error {
count = res.NbHits
}

io.StartProgressIndicatorWithLabel(fmt.Sprintf("Analyzing %d objects", count))
io.StartProgressIndicatorWithLabel(fmt.Sprintf("Analyzing %d/%d objects", limit, count))

// Chan to receive the object count
counter := make(chan int)
go func() {
var total int
for c := range counter {
total += c
io.UpdateProgressIndicatorLabel(fmt.Sprintf("Analyzing %d/%d objects", total, count))
}
close(counter)
}()

res, err := indice.BrowseObjects(opt.Query(query), opt.ExtraOptions(opts.BrowseParams))
if err != nil {
Expand All @@ -131,7 +142,7 @@ func runAnalyzeCmd(opts *StatsOptions) error {
return err
}

stats, err := analyze.ComputeStats(res, settings, limit, opts.Only)
stats, err := analyze.ComputeStats(res, settings, limit, opts.Only, counter)
if err != nil {
io.StopProgressIndicator()
return err
Expand Down

0 comments on commit f7822e6

Please sign in to comment.