fix(faq): 保留克隆状态同步时的正文和索引状态 (#3993)
parent
e29301115a
commit
7c284e7fc9
|
|
@ -104,8 +104,13 @@ func (s *knowledgeService) syncFAQChunkStatusBatch(
|
|||
metadataIDs = append(metadataIDs, dst.ID)
|
||||
}
|
||||
}
|
||||
if len(rows) > 0 {
|
||||
if err := s.chunkRepo.UpdateChunks(ctx, rows); err != nil {
|
||||
for _, row := range rows {
|
||||
// These are status-only snapshots. UpdateChunks also writes content and
|
||||
// indexing status, which are absent here and must remain unchanged.
|
||||
fields := map[string]interface{}{
|
||||
"is_enabled": row.IsEnabled, "flags": int(row.Flags), "tag_id": row.TagID,
|
||||
}
|
||||
if err := s.chunkRepo.UpdateChunkFieldsByIDs(ctx, tenantID, []string{row.ID}, fields); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +154,7 @@ func (s *knowledgeService) syncFAQChunkStatusBatch(
|
|||
}
|
||||
if len(recommendedUpdates) > 0 {
|
||||
// Vector-store recommended flag sync is not yet available on all backends in
|
||||
// this branch; DB flags were already updated via UpdateChunks above.
|
||||
// this branch; DB flags were already updated above.
|
||||
logger.Warnf(ctx, "FAQ clone sync: skipped vector recommended update for %d chunks (DB flags updated)", len(recommendedUpdates))
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFAQCloneStatusSyncPreservesContentAndIndexState(t *testing.T) {
|
||||
for _, change := range []string{"enabled", "tag", "recommended", "answer_strategy"} {
|
||||
t.Run(change, func(t *testing.T) {
|
||||
f := newFAQWriteFixture(t)
|
||||
const body = "Restart the worker to reload the configuration."
|
||||
require.NoError(t, f.db.Model(&types.Chunk{}).Where("id IN ?", []string{"one", "two"}).
|
||||
Updates(map[string]any{
|
||||
"content": body, "status": int(types.ChunkStatusIndexed),
|
||||
"tag_id": "", "flags": 0, "metadata": types.JSON(`{"answer_strategy":"all"}`),
|
||||
}).Error)
|
||||
fields := map[string]any{}
|
||||
switch change {
|
||||
case "enabled":
|
||||
fields["is_enabled"] = false
|
||||
case "tag":
|
||||
fields["tag_id"] = "foreign"
|
||||
case "recommended":
|
||||
fields["flags"] = int(types.ChunkFlagRecommended)
|
||||
case "answer_strategy":
|
||||
fields["metadata"] = types.JSON(`{"answer_strategy":"random"}`)
|
||||
}
|
||||
require.NoError(t, f.db.Model(&types.Chunk{}).Where("id = ?", "two").Updates(fields).Error)
|
||||
pairs := []types.FAQChunkSyncPair{{SrcChunkID: "two", DstChunkID: "one"}}
|
||||
resolve := func(string) string { return "tag" }
|
||||
plan, err := f.svc.buildFAQStatusSyncPlan(f.ctx, 7, 7, pairs, resolve)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, plan.Pairs, 1)
|
||||
err = f.svc.syncFAQChunkStatusBatch(f.ctx, f.kb, plan.Pairs, plan.SrcByID, plan.DstByID, resolve)
|
||||
require.NoError(t, err)
|
||||
chunk, err := f.chunks.GetChunkByID(f.ctx, 7, "one")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, body, chunk.Content)
|
||||
require.Equal(t, int(types.ChunkStatusIndexed), chunk.Status)
|
||||
plan, err = f.svc.buildFAQStatusSyncPlan(f.ctx, 7, 7, pairs, resolve)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plan.Pairs, "the requested status changes must still be applied")
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue