fix(faq): guard against division by zero in import timing logs

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wizardchen
2026-07-08 15:17:57 +08:00
committed by lyingbug
parent d9bb7aa8f2
commit a1b49e2664
@@ -1059,6 +1059,10 @@ func (s *knowledgeService) executeFAQImport(ctx context.Context, taskID string,
}
totalDuration := time.Since(totalStartTime)
var avgPerEntry time.Duration
if actualProcessed > 0 {
avgPerEntry = totalDuration / time.Duration(actualProcessed)
}
logger.Infof(
ctx,
"FAQ import task %s: all batches completed, processed: %d entries (skipped: %d) in %v, avg: %v per entry",
@@ -1066,7 +1070,7 @@ func (s *knowledgeService) executeFAQImport(ctx context.Context, taskID string,
actualProcessed,
skippedCount,
totalDuration,
totalDuration/time.Duration(actualProcessed),
avgPerEntry,
)
return nil
@@ -1417,8 +1421,12 @@ func (s *knowledgeService) indexFAQChunks(ctx context.Context,
return err
}
batchIndexDuration := time.Since(batchIndexStartTime)
var avgPerEntry time.Duration
if len(indexInfo) > 0 {
avgPerEntry = batchIndexDuration / time.Duration(len(indexInfo))
}
logger.Debugf(ctx, "indexFAQChunks: batch indexed %d index info entries in %v (avg: %v per entry)",
len(indexInfo), batchIndexDuration, batchIndexDuration/time.Duration(len(indexInfo)))
len(indexInfo), batchIndexDuration, avgPerEntry)
if adjustStorage && size > 0 {
adjustStartTime := time.Now()