fix: Update wiki index rebuilding and log entry formatting
- Modified the `rebuildWikiIndexSimple` function to include `knowledgeID` in the parameters, ensuring accurate logging of deleted pages. - Enhanced the log entry format in `appendLogEntry` to include the action type and improved timestamp formatting, providing clearer context for actions taken on wiki pages. - Adjusted the `ProcessWikiRetract` and `ProcessWikiIngest` methods to align with the new log entry structure, ensuring consistency across logging actions. These changes improve the clarity and accuracy of wiki activity logs, facilitating better tracking of content changes.
This commit is contained in:
@@ -1335,7 +1335,7 @@ func (s *knowledgeService) cleanupWikiOnKnowledgeDelete(ctx context.Context, kbI
|
|||||||
|
|
||||||
// Rebuild index page to reflect deleted pages
|
// Rebuild index page to reflect deleted pages
|
||||||
if len(deletedSlugs) > 0 {
|
if len(deletedSlugs) > 0 {
|
||||||
s.rebuildWikiIndexSimple(ctx, kbID, docTitle, deletedSlugs)
|
s.rebuildWikiIndexSimple(ctx, kbID, knowledgeID, docTitle, deletedSlugs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1356,7 +1356,7 @@ func removeSourceRef(refs types.StringArray, knowledgeID string) types.StringArr
|
|||||||
// rebuildWikiIndexSimple regenerates the index page from current page listing
|
// rebuildWikiIndexSimple regenerates the index page from current page listing
|
||||||
// and appends a deletion log entry. Does NOT use LLM — generates a simple
|
// and appends a deletion log entry. Does NOT use LLM — generates a simple
|
||||||
// structured listing. Used during document deletion when LLM is not available.
|
// structured listing. Used during document deletion when LLM is not available.
|
||||||
func (s *knowledgeService) rebuildWikiIndexSimple(ctx context.Context, kbID, docTitle string, deletedSlugs []string) {
|
func (s *knowledgeService) rebuildWikiIndexSimple(ctx context.Context, kbID, knowledgeID, docTitle string, deletedSlugs []string) {
|
||||||
// Rebuild index
|
// Rebuild index
|
||||||
resp, err := s.wikiService.ListPages(ctx, &types.WikiPageListRequest{
|
resp, err := s.wikiService.ListPages(ctx, &types.WikiPageListRequest{
|
||||||
KnowledgeBaseID: kbID,
|
KnowledgeBaseID: kbID,
|
||||||
@@ -1401,9 +1401,10 @@ func (s *knowledgeService) rebuildWikiIndexSimple(ctx context.Context, kbID, doc
|
|||||||
// Append log entry
|
// Append log entry
|
||||||
logPage, _ := s.wikiService.GetLog(ctx, kbID)
|
logPage, _ := s.wikiService.GetLog(ctx, kbID)
|
||||||
if logPage != nil {
|
if logPage != nil {
|
||||||
entry := fmt.Sprintf("\n## [%s] delete | %s\n- **Pages deleted**: %d (%s)\n",
|
entry := fmt.Sprintf("\n## [%s] delete | %s\n- **Source**: knowledge/%s\n- **Pages deleted**: %d (%s)\n",
|
||||||
time.Now().UTC().Format("2006-01-02 15:04"),
|
time.Now().UTC().Format("2006-01-02 15:04:05"),
|
||||||
docTitle,
|
docTitle,
|
||||||
|
knowledgeID,
|
||||||
len(deletedSlugs),
|
len(deletedSlugs),
|
||||||
strings.Join(deletedSlugs, ", "),
|
strings.Join(deletedSlugs, ", "),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -276,7 +276,8 @@ func (s *wikiIngestService) ProcessWikiRetract(ctx context.Context, t *asynq.Tas
|
|||||||
s.appendLogEntry(ctx, WikiIngestPayload{
|
s.appendLogEntry(ctx, WikiIngestPayload{
|
||||||
TenantID: payload.TenantID,
|
TenantID: payload.TenantID,
|
||||||
KnowledgeBaseID: payload.KnowledgeBaseID,
|
KnowledgeBaseID: payload.KnowledgeBaseID,
|
||||||
}, payload.DocTitle+" [DELETED]", payload.PageSlugs, nil)
|
KnowledgeID: payload.KnowledgeID,
|
||||||
|
}, "retract", payload.DocTitle, payload.PageSlugs, "")
|
||||||
|
|
||||||
// Clean up dead links pointing to archived/deleted pages
|
// Clean up dead links pointing to archived/deleted pages
|
||||||
s.cleanDeadLinks(ctx, payload.KnowledgeBaseID)
|
s.cleanDeadLinks(ctx, payload.KnowledgeBaseID)
|
||||||
@@ -362,7 +363,6 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pagesAffected []string
|
var pagesAffected []string
|
||||||
var synthesisSuggestions []string
|
|
||||||
|
|
||||||
// Format source ref as "knowledgeID|docTitle" for frontend display
|
// Format source ref as "knowledgeID|docTitle" for frontend display
|
||||||
sourceRef := fmt.Sprintf("%s|%s", payload.KnowledgeID, docTitle)
|
sourceRef := fmt.Sprintf("%s|%s", payload.KnowledgeID, docTitle)
|
||||||
@@ -415,16 +415,13 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Detect synthesis opportunities (no LLM call, pure heuristic)
|
// Step 3: Rebuild index page
|
||||||
synthesisSuggestions = s.detectSynthesisOpportunities(ctx, payload)
|
|
||||||
|
|
||||||
// Step 4: Rebuild index page
|
|
||||||
if err := s.rebuildIndexPage(ctx, chatModel, payload, lang); err != nil {
|
if err := s.rebuildIndexPage(ctx, chatModel, payload, lang); err != nil {
|
||||||
logger.Warnf(ctx, "wiki ingest: rebuild index failed: %v", err)
|
logger.Warnf(ctx, "wiki ingest: rebuild index failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5: Append to log page with synthesis suggestions
|
// Step 4: Append to log page
|
||||||
s.appendLogEntry(ctx, payload, docTitle, pagesAffected, synthesisSuggestions)
|
s.appendLogEntry(ctx, payload, "ingest", docTitle, pagesAffected, "")
|
||||||
|
|
||||||
// Step 6: Cross-link injection — scan all affected pages and inject [[wiki-links]]
|
// Step 6: Cross-link injection — scan all affected pages and inject [[wiki-links]]
|
||||||
// for mentions of other wiki page titles. Pure text matching, no LLM call.
|
// for mentions of other wiki page titles. Pure text matching, no LLM call.
|
||||||
@@ -1010,28 +1007,30 @@ func (s *wikiIngestService) rebuildIndexPage(ctx context.Context, chatModel chat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// appendLogEntry appends an entry to the log page, including any synthesis suggestions
|
// appendLogEntry appends an entry to the log page, including any synthesis suggestions
|
||||||
func (s *wikiIngestService) appendLogEntry(ctx context.Context, payload WikiIngestPayload, docTitle string, pagesAffected []string, suggestions []string) {
|
// appendLogEntry appends a structured, grep-parseable entry to the log page.
|
||||||
|
// Format: ## [2026-04-07 19:50:02] action | title
|
||||||
|
// Followed by key-value metadata lines. No sub-headings — keeps `grep "^## \[" log.md` clean.
|
||||||
|
func (s *wikiIngestService) appendLogEntry(ctx context.Context, payload WikiIngestPayload, action, docTitle string, pagesAffected []string, extra string) {
|
||||||
logPage, _ := s.wikiService.GetLog(ctx, payload.KnowledgeBaseID)
|
logPage, _ := s.wikiService.GetLog(ctx, payload.KnowledgeBaseID)
|
||||||
if logPage == nil {
|
if logPage == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
entry := fmt.Sprintf("\n## [%s] ingest | %s\n- **Source**: knowledge/%s\n- **Pages affected**: %d (%s)\n",
|
var sb strings.Builder
|
||||||
time.Now().UTC().Format("2006-01-02 15:04"),
|
fmt.Fprintf(&sb, "\n## [%s] %s | %s\n",
|
||||||
|
time.Now().UTC().Format("2006-01-02 15:04:05"),
|
||||||
|
action,
|
||||||
docTitle,
|
docTitle,
|
||||||
payload.KnowledgeID,
|
|
||||||
len(pagesAffected),
|
|
||||||
strings.Join(pagesAffected, ", "),
|
|
||||||
)
|
)
|
||||||
|
fmt.Fprintf(&sb, "- **Source**: knowledge/%s\n", payload.KnowledgeID)
|
||||||
if len(suggestions) > 0 {
|
if len(pagesAffected) > 0 {
|
||||||
entry += "\n### Synthesis Opportunities\n"
|
fmt.Fprintf(&sb, "- **Pages affected**: %d (%s)\n", len(pagesAffected), strings.Join(pagesAffected, ", "))
|
||||||
for _, suggestion := range suggestions {
|
}
|
||||||
entry += fmt.Sprintf("- %s\n", suggestion)
|
if extra != "" {
|
||||||
}
|
sb.WriteString(extra)
|
||||||
}
|
}
|
||||||
|
|
||||||
logPage.Content = logPage.Content + entry
|
logPage.Content = logPage.Content + sb.String()
|
||||||
if _, err := s.wikiService.UpdatePage(ctx, logPage); err != nil {
|
if _, err := s.wikiService.UpdatePage(ctx, logPage); err != nil {
|
||||||
logger.Warnf(ctx, "wiki ingest: failed to update log page: %v", err)
|
logger.Warnf(ctx, "wiki ingest: failed to update log page: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user