Skip to content

Commit c10b6bf

Browse files
author
razvan
committed
fix: use CountAllFiles for accurate on_disk metrics in index_status.json
The Progress callback received totalFiles = len(changedFiles), which only counts modified files needing re-indexing. This was incorrectly assigned to OnDisk, causing on_disk: 1 when only 1 file changed — despite 232 Go files and 655 docs on disk. Fix: - Call CountAllFiles() once before the language loop for real disk totals - Pre-populate index_status.json with on_disk counts at indexing start - Use diskTotal (pre-counted) for OnDisk, totalFiles for Changed - Languages with 0 changed files now correctly show their disk totals
1 parent 5198fe5 commit c10b6bf

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

internal/service/engine/engine.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,33 @@ func (e *Engine) IndexWorkspace(ctx context.Context, path string, recreate bool)
888888
excludePatterns = e.config.Workspace.ExcludePatterns
889889
}
890890

891+
// Pre-count total files per language with a single WalkDir pass.
892+
// This gives us the real on_disk totals for accurate progress reporting,
893+
// instead of using len(changedFiles) which only reflects modified files.
894+
fileCounts := e.indexer.CountAllFiles(wctx.Root, excludePatterns)
895+
logger.Instance.Info("[IDX] ws=%s file counts: %v", wsName, fileCounts)
896+
897+
// Pre-populate index_status.json with the real disk totals so that
898+
// even languages with 0 changed files still show correct on_disk counts.
899+
{
900+
s := indexer.LoadIndexStatus(wctx.Root)
901+
if s == nil {
902+
s = &indexer.IndexStatus{State: "starting", StartedAt: time.Now().UTC().Format(time.RFC3339)}
903+
}
904+
if s.Languages == nil {
905+
s.Languages = make(map[string]indexer.LangStatus)
906+
}
907+
for _, lang := range languages {
908+
s.Languages[lang] = indexer.LangStatus{OnDisk: fileCounts[lang]}
909+
}
910+
indexer.SaveIndexStatus(wctx.Root, s)
911+
}
912+
891913
var indexErrors []string
892914
for _, lang := range languages {
915+
diskTotal := fileCounts[lang]
893916
collection := wctx.CollectionName(lang)
894-
logger.Instance.Info("[IDX] ws=%s lang=%s ▶ starting", wsName, lang)
917+
logger.Instance.Info("[IDX] ws=%s lang=%s ▶ starting (on_disk=%d)", wsName, lang, diskTotal)
895918
err := e.indexer.IndexWorkspace(ctx, wctx.Root, collection, indexer.Options{
896919
Language: lang,
897920
WorkspaceName: wsName,
@@ -904,8 +927,8 @@ func (e *Engine) IndexWorkspace(ctx context.Context, path string, recreate bool)
904927
s.Languages = make(map[string]indexer.LangStatus)
905928
}
906929
ls := s.Languages[lang]
907-
ls.OnDisk = totalFiles
908-
ls.Changed = totalFiles
930+
ls.OnDisk = diskTotal // real total files on disk for this language
931+
ls.Changed = totalFiles // files that needed re-indexing (changedFiles)
909932
ls.Processed = doneFiles
910933
s.Languages[lang] = ls
911934
indexer.SaveIndexStatus(wctx.Root, s)

0 commit comments

Comments
 (0)