From a4c3c3955680a65be4168408c8336581f8939d22 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Fri, 8 May 2026 15:04:11 +0800 Subject: [PATCH] perf(wiki): lazy-load sidebar page list with virtual-scroll tabs ?tab=wiki used to call listWikiPages({page_size: 500}) in a loop up to 50 times, loading ~25k pages into memory before rendering the sidebar on knowledge bases with tens of thousands of pages. All rows were then materialized as DOM nodes inside collapsible groups stacked vertically. This commit reshapes the sidebar around per-type buckets that are fetched on demand and rendered through a single virtual scroller: * pagesByType holds one bucket per page_type (summary / entity / concept / synthesis / comparison), each with its own items list, pagination cursor, KB-wide total, and loading flag. Initial load fires one 50-item request per type in parallel. * Index and Log are fetched directly via getWikiIndex / getWikiLog instead of scanning the full page list to find them. * Groups are surfaced as a horizontal tab bar; switching tabs swaps the RecycleScroller's items. Only one bucket is visible at a time, so we never stack multiple virtual viewports. * The scroller runs in page-mode with the outer .wiki-page-list as the scrollable ancestor; a 1px sentinel after the list is watched by IntersectionObserver to trigger the next page fetch. After each batch lands we call scroller.updateVisibleItems(true) on the next tick so appended rows render in order without requiring the user to jiggle the scroll. * Switching tabs resets scrollTop so the retained position of the previous tab can't re-trigger the sentinel and cascade loads on the new (shorter) list. * Search enters a dedicated flat-result mode (searchResults ref); clearing the query flips back to the bucketed view without refetching the buckets the user already had open. Adds vue-virtual-scroller dependency and imports its stylesheet. --- frontend/package-lock.json | 19 + frontend/package.json | 1 + frontend/src/i18n/locales/en-US.ts | 2 + frontend/src/i18n/locales/ko-KR.ts | 2 + frontend/src/i18n/locales/ru-RU.ts | 2 + frontend/src/i18n/locales/zh-CN.ts | 2 + frontend/src/main.ts | 4 + .../src/views/knowledge/wiki/WikiBrowser.vue | 646 ++++++++++++++---- 8 files changed, 532 insertions(+), 146 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 54a09e59..1ca71933 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -30,6 +30,7 @@ "vue-demi": "^0.14.6", "vue-i18n": "^11.1.12", "vue-router": "^4.5.0", + "vue-virtual-scroller": "^2.0.0-beta.8", "webpack": "^5.94.0", "xlsx": "file:./packages/xlsx-0.20.2.tgz" }, @@ -5186,6 +5187,24 @@ "typescript": ">=5.0.0" } }, + "node_modules/vue-virtual-scroller": { + "version": "2.0.1", + "resolved": "https://mirrors.tencent.com/npm/vue-virtual-scroller/-/vue-virtual-scroller-2.0.1.tgz", + "integrity": "sha512-3Drq8C61C4B3reSaZJr5nXBf/B7Beq1+h5/kYZB25MLYljTy97ISeUufRX9z6ZSZlFDXyafAOLK9XwajOWJY1A==", + "license": "MIT", + "dependencies": { + "mitt": "^2.1.0" + }, + "peerDependencies": { + "vue": "^3.3.0" + } + }, + "node_modules/vue-virtual-scroller/node_modules/mitt": { + "version": "2.1.0", + "resolved": "https://mirrors.tencent.com/npm/mitt/-/mitt-2.1.0.tgz", + "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==", + "license": "MIT" + }, "node_modules/watchpack": { "version": "2.5.1", "resolved": "https://mirrors.tencent.com/npm/watchpack/-/watchpack-2.5.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 34e2bc6c..a7bd9af3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -34,6 +34,7 @@ "vue-demi": "^0.14.6", "vue-i18n": "^11.1.12", "vue-router": "^4.5.0", + "vue-virtual-scroller": "^2.0.0-beta.8", "webpack": "^5.94.0", "xlsx": "file:./packages/xlsx-0.20.2.tgz" }, diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index faa3db37..9e531151 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -1684,6 +1684,8 @@ export default { tabWiki: 'Wiki', tabGraph: 'Graph', searchPlaceholder: 'Search wiki pages...', + searchNoResults: 'No matching pages found', + loadMore: 'Load more ({remaining} remaining)', filterAll: 'All Types', filterSummary: 'Summaries', filterEntity: 'Entities', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 8a9a2498..1bac023d 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -2296,6 +2296,8 @@ export default { tabWiki: "Wiki", tabGraph: "그래프", searchPlaceholder: "Wiki 페이지 검색...", + searchNoResults: "일치하는 페이지가 없습니다", + loadMore: "더 불러오기 ({remaining}개 남음)", filterAll: "전체 유형", filterSummary: "요약", filterEntity: "엔티티", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index c615c9f7..41b27e8e 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -1906,6 +1906,8 @@ export default { tabWiki: 'Wiki', tabGraph: 'Граф', searchPlaceholder: 'Поиск Wiki-страниц...', + searchNoResults: 'Страницы не найдены', + loadMore: 'Загрузить ещё (осталось {remaining})', filterAll: 'Все типы', filterSummary: 'Резюме', filterEntity: 'Сущности', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 262d08a5..306ae160 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -2267,6 +2267,8 @@ export default { tabWiki: "Wiki", tabGraph: "图谱", searchPlaceholder: "搜索 Wiki 页面...", + searchNoResults: "没有找到匹配的页面", + loadMore: "加载更多(还剩 {remaining} 条)", filterAll: "全部类型", filterSummary: "摘要", filterEntity: "实体", diff --git a/frontend/src/main.ts b/frontend/src/main.ts index d797d3a0..075131de 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -8,6 +8,10 @@ import TDesign from "tdesign-vue-next"; import "tdesign-vue-next/es/style/index.css"; import "@/assets/theme/theme.css"; import "@/assets/dropdown-menu.less"; +// vue-virtual-scroller ships its own tiny stylesheet — required for +// RecycleScroller/DynamicScroller to size their viewport correctly. +// Without it the scroller computes 0 height and renders no items. +import "vue-virtual-scroller/dist/vue-virtual-scroller.css"; import i18n from "./i18n"; import { initTheme } from "@/composables/useTheme"; import { initFont } from "@/composables/useFont"; diff --git a/frontend/src/views/knowledge/wiki/WikiBrowser.vue b/frontend/src/views/knowledge/wiki/WikiBrowser.vue index 7ad9e790..6eb13951 100644 --- a/frontend/src/views/knowledge/wiki/WikiBrowser.vue +++ b/frontend/src/views/knowledge/wiki/WikiBrowser.vue @@ -213,73 +213,121 @@ :placeholder="$t('knowledgeEditor.wikiBrowser.searchPlaceholder')" clearable @enter="doSearch" - @clear="loadPages" + @clear="searchResults = null" > -
- -
- - {{ $t('knowledgeEditor.wikiBrowser.indexTitle') }} -
- - -
- - {{ $t('knowledgeEditor.wikiBrowser.logTitle') }} -
- -
- - -