feat: Implement auto-linked content updates in wiki page management

- Introduced UpdateAutoLinkedContent method to persist changes from machine-only link decorators without incrementing the version number, ensuring user-facing revisions remain consistent.
- Updated existing methods to utilize the new auto-linked content update logic, enhancing the handling of cross-link injection and dead-link cleanup.
- Enhanced the KnowledgeBase and WikiBrowser components to improve user experience during wiki operations, including status tracking and indexing indicators.
- Added scheduling for wiki status probes to provide timely feedback on indexing processes after user-triggered actions.
This commit is contained in:
wizardchen
2026-04-23 11:16:47 +08:00
parent d305d5eb7c
commit c5494f612b
7 changed files with 119 additions and 5 deletions
@@ -59,6 +59,30 @@ func (r *wikiPageRepository) Update(ctx context.Context, page *types.WikiPage) e
return nil
}
// UpdateAutoLinkedContent persists content changes produced by the automatic
// link decorators (cross-link injection, dead-link cleanup) without bumping
// `version`. These passes rewrite the same revision with wiki-link markup
// added or removed; treating them as real edits would make newly-ingested
// pages appear as v2 on first view and confuse users who expect `version` to
// correspond to the number of intentional revisions.
func (r *wikiPageRepository) UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error {
result := r.db.WithContext(ctx).
Model(page).
Where("id = ?", page.ID).
Updates(map[string]interface{}{
"content": page.Content,
"out_links": page.OutLinks,
"updated_at": page.UpdatedAt,
})
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return ErrWikiPageNotFound
}
return nil
}
// UpdateMeta updates bookkeeping / provenance fields WITHOUT incrementing the
// version number. "Content" for versioning purposes is the user-visible page
// body (title/content/summary/page_type/status); everything else — links,
+2 -2
View File
@@ -460,7 +460,7 @@ func (s *wikiIngestService) cleanDeadLinks(ctx context.Context, kbID string) {
if changed {
p.Content = content
if _, err := s.wikiService.UpdatePage(ctx, p); err != nil {
if err := s.wikiService.UpdateAutoLinkedContent(ctx, p); err != nil {
logger.Warnf(ctx, "wiki: failed to clean dead links in page %s: %v", p.Slug, err)
} else {
cleaned++
@@ -509,7 +509,7 @@ func (s *wikiIngestService) injectCrossLinks(ctx context.Context, kbID string, a
continue
}
p.Content = newContent
if _, err := s.wikiService.UpdatePage(ctx, p); err != nil {
if err := s.wikiService.UpdateAutoLinkedContent(ctx, p); err != nil {
logger.Warnf(ctx, "wiki ingest: cross-link injection failed for %s: %v", p.Slug, err)
continue
}
+1 -1
View File
@@ -339,7 +339,7 @@ func (s *WikiLintService) AutoFix(ctx context.Context, kbID string) (int, error)
}
target := issue.TargetSlug
page.Content = strings.ReplaceAll(page.Content, "[["+target+"]]", target)
if _, err := s.wikiService.UpdatePage(ctx, page); err == nil {
if err := s.wikiService.UpdateAutoLinkedContent(ctx, page); err == nil {
fixed++
}
+28 -1
View File
@@ -144,6 +144,33 @@ func (s *wikiPageService) UpdatePageMeta(ctx context.Context, page *types.WikiPa
return s.repo.UpdateMeta(ctx, page)
}
// UpdateAutoLinkedContent persists content produced by machine-only link
// decorators (cross-link injection / dead-link cleanup) without bumping
// `version`. Out-links are re-parsed from the new body and bidirectional
// in-link references on target pages are refreshed so link navigation stays
// consistent — only the user-facing revision counter is preserved.
func (s *wikiPageService) UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error {
existing, err := s.repo.GetBySlug(ctx, page.KnowledgeBaseID, page.Slug)
if err != nil {
return fmt.Errorf("get existing page: %w", err)
}
oldOutLinks := existing.OutLinks
existing.Content = page.Content
existing.OutLinks = s.parseOutLinks(existing.Content)
existing.UpdatedAt = time.Now()
if err := s.repo.UpdateAutoLinkedContent(ctx, existing); err != nil {
return fmt.Errorf("update auto-linked content: %w", err)
}
s.removeInLinks(ctx, existing.KnowledgeBaseID, existing.Slug, oldOutLinks)
s.updateInLinks(ctx, existing.KnowledgeBaseID, existing.Slug, existing.OutLinks)
return nil
}
// GetPageBySlug retrieves a wiki page by its slug
func (s *wikiPageService) GetPageBySlug(ctx context.Context, kbID string, slug string) (*types.WikiPage, error) {
return s.repo.GetBySlug(ctx, kbID, slug)
@@ -573,7 +600,7 @@ func (s *wikiPageService) InjectCrossLinks(ctx context.Context, kbID string, aff
continue
}
p.Content = newContent
if _, err := s.UpdatePage(ctx, p); err != nil {
if err := s.UpdateAutoLinkedContent(ctx, p); err != nil {
logger.Warnf(ctx, "wiki: cross-link injection failed for %s: %v", p.Slug, err)
continue
}