fix(faq): guard against division by zero in import timing logs
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1059,6 +1059,10 @@ func (s *knowledgeService) executeFAQImport(ctx context.Context, taskID string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
totalDuration := time.Since(totalStartTime)
|
totalDuration := time.Since(totalStartTime)
|
||||||
|
var avgPerEntry time.Duration
|
||||||
|
if actualProcessed > 0 {
|
||||||
|
avgPerEntry = totalDuration / time.Duration(actualProcessed)
|
||||||
|
}
|
||||||
logger.Infof(
|
logger.Infof(
|
||||||
ctx,
|
ctx,
|
||||||
"FAQ import task %s: all batches completed, processed: %d entries (skipped: %d) in %v, avg: %v per entry",
|
"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,
|
actualProcessed,
|
||||||
skippedCount,
|
skippedCount,
|
||||||
totalDuration,
|
totalDuration,
|
||||||
totalDuration/time.Duration(actualProcessed),
|
avgPerEntry,
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -1417,8 +1421,12 @@ func (s *knowledgeService) indexFAQChunks(ctx context.Context,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
batchIndexDuration := time.Since(batchIndexStartTime)
|
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)",
|
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 {
|
if adjustStorage && size > 0 {
|
||||||
adjustStartTime := time.Now()
|
adjustStartTime := time.Now()
|
||||||
|
|||||||
Reference in New Issue
Block a user