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:
@@ -69,12 +69,17 @@ const onWikiStatusChange = (payload: { pendingTasks: number; isActive: boolean;
|
||||
}
|
||||
|
||||
let wikiStatusTimer: ReturnType<typeof setInterval> | null = null
|
||||
let wikiStatusProbeTimers: Array<ReturnType<typeof setTimeout>> = []
|
||||
const stopWikiStatusPolling = () => {
|
||||
if (wikiStatusTimer) {
|
||||
clearInterval(wikiStatusTimer)
|
||||
wikiStatusTimer = null
|
||||
}
|
||||
}
|
||||
const clearWikiStatusProbes = () => {
|
||||
wikiStatusProbeTimers.forEach(t => clearTimeout(t))
|
||||
wikiStatusProbeTimers = []
|
||||
}
|
||||
const fetchWikiStatusOnce = async () => {
|
||||
if (!kbId.value || !isWiki.value) return
|
||||
try {
|
||||
@@ -96,14 +101,31 @@ const fetchWikiStatusOnce = async () => {
|
||||
}
|
||||
} catch (_) { /* ignore */ }
|
||||
}
|
||||
// 用户刚触发了一个上传 / reparse / URL 导入之类的动作后,后台通常要过
|
||||
// 一小段时间才会把 wiki 任务真正塞进队列;如果这时空闲轮询刚好停了,
|
||||
// 面包屑的"索引中"会延迟很久才亮起。所以这里安排几次退避重试,
|
||||
// 主动把面包屑的 loading 尽快点亮,一旦探测到任务就会走正常的 5s 轮询。
|
||||
const scheduleWikiStatusProbes = () => {
|
||||
if (!kbId.value || !isWiki.value) return
|
||||
clearWikiStatusProbes()
|
||||
const delays = [500, 2000, 5000, 10000]
|
||||
delays.forEach(delay => {
|
||||
const timer = setTimeout(() => { fetchWikiStatusOnce() }, delay)
|
||||
wikiStatusProbeTimers.push(timer)
|
||||
})
|
||||
}
|
||||
watch([kbId, isWiki], ([newKbId, newIsWiki]) => {
|
||||
stopWikiStatusPolling()
|
||||
clearWikiStatusProbes()
|
||||
wikiStatus.value = { pendingTasks: 0, isActive: false, pendingIssues: 0 }
|
||||
if (newKbId && newIsWiki) {
|
||||
fetchWikiStatusOnce()
|
||||
}
|
||||
}, { immediate: true })
|
||||
onUnmounted(stopWikiStatusPolling)
|
||||
onUnmounted(() => {
|
||||
stopWikiStatusPolling()
|
||||
clearWikiStatusProbes()
|
||||
})
|
||||
const missingStorageEngine = computed(() => {
|
||||
if (!kbInfo.value || isFAQ.value) return false
|
||||
const spc = kbInfo.value.storage_provider_config
|
||||
@@ -737,6 +759,8 @@ const handleFileUploaded = (event: CustomEvent) => {
|
||||
page = 1; // Reset page counter when reloading files after upload
|
||||
loadKnowledgeFiles(uploadedKbId);
|
||||
loadTags(uploadedKbId);
|
||||
// 启动几次探测,尽快让面包屑的"索引中"亮起。
|
||||
scheduleWikiStatusProbes();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1541,6 +1565,8 @@ const rebuildConfirm = async () => {
|
||||
MessagePlugin.success(t('knowledgeBase.rebuildSubmitted'));
|
||||
page = 1; // Reset page counter when reloading files after reparse
|
||||
loadKnowledgeFiles(kbId.value);
|
||||
// reparse 同样会触发 wiki 重入队,探测一下让面包屑尽快亮起。
|
||||
scheduleWikiStatusProbes();
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('knowledgeBase.rebuildFailed'));
|
||||
}
|
||||
|
||||
@@ -2140,6 +2140,27 @@ onUnmounted(() => {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.wiki-reader-aliases {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 8px;
|
||||
margin: 0 0 10px;
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.wiki-alias-label {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.wiki-alias-tag {
|
||||
// Slight vertical nudge so the tag baseline lines up with the label.
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wiki-reader-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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++
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -27,6 +27,15 @@ type WikiPageService interface {
|
||||
// ref changes driven by internal reconciliation.
|
||||
UpdatePageMeta(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// UpdateAutoLinkedContent persists content changes that come from
|
||||
// machine-only link decoration — cross-link injection and 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. Conceptually the body still represents the same revision
|
||||
// the user saw before, just with wiki-link markup added or stripped, so
|
||||
// surfacing a version bump to end users is misleading.
|
||||
UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// GetPageBySlug retrieves a wiki page by its slug within a knowledge base.
|
||||
GetPageBySlug(ctx context.Context, kbID string, slug string) (*types.WikiPage, error)
|
||||
|
||||
@@ -103,6 +112,13 @@ type WikiPageRepository interface {
|
||||
// unchanged body, and status-only transitions.
|
||||
UpdateMeta(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// UpdateAutoLinkedContent rewrites `content`, `out_links` and
|
||||
// `updated_at` in place while leaving `version` untouched. Intended for
|
||||
// machine-only link markup changes (cross-link injection / dead-link
|
||||
// cleanup) so the first-ingest page doesn't jump to v2 just because the
|
||||
// post-processor added a `[[...]]` wrapper.
|
||||
UpdateAutoLinkedContent(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// GetByID retrieves a wiki page by its unique ID.
|
||||
GetByID(ctx context.Context, id string) (*types.WikiPage, error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user