mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-16 21:50:58 +08:00
fix: return total number of docs when sync has no update (#18255)
### Summary As title --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -333,7 +333,7 @@ func (d *SyncTaskDAO) CompleteSyncTask(ctx context.Context, taskContext SyncTask
|
||||
"status": SyncStatusDone,
|
||||
"poll_range_end": entity.FlexibleTime(pollRangeEnd),
|
||||
"new_docs_indexed": newDocs,
|
||||
"total_docs_indexed": gorm.Expr("total_docs_indexed + ?", totalDocs),
|
||||
"total_docs_indexed": totalDocs,
|
||||
"error_msg": errorMsg,
|
||||
"error_count": errorCount,
|
||||
})
|
||||
|
||||
@@ -434,7 +434,7 @@ func (h *ConnectorHandler) RebuildConnector(c *gin.Context) {
|
||||
common.SuccessWithData(c, ok, "success")
|
||||
}
|
||||
|
||||
// ResumeFailedSync resumes a failed connector sync task from checkpoint.
|
||||
// ResumeFailedSync resumes a failed connector sync task from checkpoint. (when network outage)
|
||||
// @Summary Resume Failed Connector Sync
|
||||
// @Description Resume a failed connector sync task from its saved checkpoint
|
||||
// @Tags connector
|
||||
|
||||
@@ -626,7 +626,6 @@ func (r *Router) Setup(engine *gin.Engine) {
|
||||
{
|
||||
connectors.GET("", r.connectorHandler.ListConnectors)
|
||||
connectors.POST("", r.connectorHandler.CreateConnector)
|
||||
// Sync logs for the current user, optionally filtered by dataset.
|
||||
connectors.GET("/sync_logs", r.connectorHandler.ListSyncLogs)
|
||||
connectors.POST("/google/oauth/web/start", r.connectorHandler.StartGoogleWebOAuth)
|
||||
connectors.POST("/google/oauth/web/result", r.connectorHandler.PollGoogleWebOAuthResult)
|
||||
|
||||
@@ -143,7 +143,7 @@ func (s *SyncTaskService) HandleTransientFailure(ctx context.Context, taskID, co
|
||||
// CompleteSync commits a successful SYNC task and schedules the next one.
|
||||
func (s *SyncTaskService) CompleteSync(ctx context.Context, taskContext SyncTaskContext, pollRangeEnd time.Time, stats SyncStats) (string, error) {
|
||||
changed := stats.Added + stats.Updated
|
||||
return s.taskDAO.CompleteSyncTask(ctx, taskContext, pollRangeEnd, changed, changed, stats.ErrorCount, stats.ErrorMsg)
|
||||
return s.taskDAO.CompleteSyncTask(ctx, taskContext, pollRangeEnd, stats.Added, changed, stats.ErrorCount, stats.ErrorMsg)
|
||||
}
|
||||
|
||||
// CompletePrune commits a successful PRUNE task and schedules the next one.
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// Factory creates a connector for a task context.
|
||||
type Factory func(ctx context.Context, taskContext any) (Connector, error)
|
||||
|
||||
// Registry maps Python connector source names to Go connector factories.
|
||||
// Registry connector source names to Go connector factories.
|
||||
type Registry struct {
|
||||
mu sync.RWMutex
|
||||
factories map[string]Factory
|
||||
|
||||
@@ -794,7 +794,12 @@ func TestHash128MatchesPythonGolden(t *testing.T) {
|
||||
func TestFingerprintSkipsUnchangedDocument(t *testing.T) {
|
||||
db := setupSyncerDB(t)
|
||||
insertTaskContext(t, db, "conn-1", "kb-1", "task-1", dao.TaskTypeSync)
|
||||
_ = db.Model(&entity.SyncLogs{}).Where("id = ?", "task-1").Update("status", dao.SyncStatusRunning).Error
|
||||
if err := db.Model(&entity.SyncLogs{}).Where("id = ?", "task-1").Updates(map[string]any{
|
||||
"status": dao.SyncStatusRunning,
|
||||
"total_docs_indexed": int64(1),
|
||||
}).Error; err != nil {
|
||||
t.Fatalf("set running task: %v", err)
|
||||
}
|
||||
taskService := service.NewSyncTaskService(dao.NewSyncTaskDAO(db))
|
||||
legacyID := service.Hash128("conn-1:source-1")
|
||||
store := fakeStore{ids: map[string]struct{}{legacyID: {}}, fingerprints: map[string]string{legacyID: "fp-1"}}
|
||||
@@ -808,6 +813,20 @@ func TestFingerprintSkipsUnchangedDocument(t *testing.T) {
|
||||
if sink.callCount() != 0 {
|
||||
t.Fatalf("sink calls = %d, want 0", sink.callCount())
|
||||
}
|
||||
var completed entity.SyncLogs
|
||||
if err := db.First(&completed, "id = ?", "task-1").Error; err != nil {
|
||||
t.Fatalf("load completed task: %v", err)
|
||||
}
|
||||
if completed.NewDocsIndexed != 0 || completed.TotalDocsIndexed != 0 {
|
||||
t.Fatalf("completed stats new/total = %d/%d, want 0/0", completed.NewDocsIndexed, completed.TotalDocsIndexed)
|
||||
}
|
||||
var next entity.SyncLogs
|
||||
if err := db.Where("id <> ? AND connector_id = ? AND kb_id = ? AND task_type = ? AND status = ?", "task-1", "conn-1", "kb-1", dao.TaskTypeSync, dao.SyncStatusSchedule).First(&next).Error; err != nil {
|
||||
t.Fatalf("load next scheduled task: %v", err)
|
||||
}
|
||||
if next.TotalDocsIndexed != 1 {
|
||||
t.Fatalf("next scheduled total docs indexed = %d, want 1", next.TotalDocsIndexed)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAutoParseFlagFlowsToSink verifies connector2kb.auto_parse is preserved.
|
||||
|
||||
Reference in New Issue
Block a user