fix: record generated wiki page versions (#17931)

This commit is contained in:
buua436
2026-08-06 16:49:50 +08:00
committed by GitHub
parent 7d0d1ab642
commit 8379165c12
7 changed files with 190 additions and 25 deletions

View File

@@ -3174,7 +3174,7 @@ async def update_wiki_page(
content_before = ""
try:
res = settings.docStoreConn.search(
select_fields=["id", "content_with_weight"],
select_fields=["id", "md_with_weight", "content_with_weight"],
highlight_fields=[],
condition={
"compile_kwd": [WIKI_PAGE_COMPILE_KWD],
@@ -3190,11 +3190,11 @@ async def update_wiki_page(
)
field_map = settings.docStoreConn.get_fields(
res,
["id", "content_with_weight"],
["id", "md_with_weight", "content_with_weight"],
)
if field_map:
row_id, row = next(iter(field_map.items()))
content_before = row.get("content_with_weight") or ""
content_before = row.get("md_with_weight") or row.get("content_with_weight") or ""
except Exception:
logging.exception(
"update_wiki_page: lookup failed for kb=%s slug=%s",
@@ -3215,6 +3215,7 @@ async def update_wiki_page(
ok = settings.docStoreConn.update(
{"id": row_id},
{
"md_with_weight": rendered,
"content_with_weight": rendered,
"summary_with_weight": summary,
"outlinks_kwd": list(outlinks),
@@ -3233,6 +3234,17 @@ async def update_wiki_page(
if not ok:
return True, None
refresh_idx = getattr(settings.docStoreConn, "refresh_idx", None)
if callable(refresh_idx):
try:
await thread_pool_exec(refresh_idx, index_nm)
except Exception:
logging.exception(
"update_wiki_page: index refresh failed for kb=%s slug=%s",
dataset_id,
full_slug,
)
# Record a file_commit row on every real change. ``record_page_edit``
# returns None for empty-diff saves, which we silently swallow.
try:
@@ -3824,4 +3836,18 @@ async def clear_wiki(dataset_id: str, tenant_id: str):
)
deleted[kwd] = False
from api.db.services.file_commit_service import FileCommitService
if all(result is not False for result in deleted.values()):
try:
deleted["file_commit_history"] = FileCommitService.delete_all_page_history(dataset_id)
except Exception:
logging.exception(
"clear_wiki: failed to delete page version history for kb=%s",
dataset_id,
)
deleted["file_commit_history"] = False
else:
deleted["file_commit_history"] = False
return True, {"deleted": deleted}