refactor(search): single-source the new-index log message

This commit is contained in:
Dominik Schmidt
2026-07-29 22:07:10 +02:00
parent 740bd05116
commit 589b69b2ef
3 changed files with 9 additions and 2 deletions

View File

@@ -46,7 +46,7 @@ func NewIndex(root string, logger log.Logger) (bleve.Index, searchmapping.Classi
return nil, searchmapping.Classification{}, err
}
logger.Info().Str("index", destination).Msg("created a new empty search index; if this OpenCloud instance already held files, they are not in it yet, index them by running: opencloud search index --all-spaces --force-rescan")
searchmapping.LogNewIndexCreated(logger, destination)
return index, searchmapping.Classification{Verdict: searchmapping.VerdictEqual}, nil
}
if err != nil {

View File

@@ -43,3 +43,10 @@ func Reconcile(index string, r SchemaReconciler, logger log.Logger) (Classificat
return classification, nil
}
// LogNewIndexCreated logs that a fresh, empty index was created and how to
// backfill it. Both backends call it after creating their index (that path does
// not run through Reconcile); an existing, up-to-date index stays silent.
func LogNewIndexCreated(logger log.Logger, index string) {
logger.Info().Str("index", index).Msg("created a new empty search index; if this OpenCloud instance already held files, they are not in it yet, index them by running: opencloud search index --all-spaces --force-rescan")
}

View File

@@ -127,7 +127,7 @@ func (m IndexManager) Apply(ctx context.Context, name string, client *opensearch
var structErr *opensearchgo.StructError
switch {
case createErr == nil && createResp.Acknowledged:
logger.Info().Str("index", name).Msg("created a new empty search index; if this OpenCloud instance already held files, they are not in it yet, index them by running: opencloud search index --all-spaces --force-rescan")
searchmapping.LogNewIndexCreated(logger, name)
return nil
case createErr == nil:
return fmt.Errorf("failed to create index %s: not acknowledged", name)