Skip to content

fix: paginate knowledge base dashboard lists#9055

Open
lxfight wants to merge 2 commits into
AstrBotDevs:masterfrom
lxfight:fix/knowledge-base-display
Open

fix: paginate knowledge base dashboard lists#9055
lxfight wants to merge 2 commits into
AstrBotDevs:masterfrom
lxfight:fix/knowledge-base-display

Conversation

@lxfight

@lxfight lxfight commented Jun 27, 2026

Copy link
Copy Markdown
Member

Fixes the native knowledge base dashboard only showing the first page/default subset of knowledge bases and documents.

Modifications / 改动点

  • Added paginated loading for the native knowledge base list, including total count handling and page fallback after deletion.

  • Switched the knowledge base document table to server-side pagination so all documents can be navigated.

  • Returned total from knowledge base and document list service responses while preserving the existing items/page/page_size shape.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

uv run ruff format .
uv run ruff check .
cd dashboard && pnpm typecheck
uv run pytest tests/test_kb_import.py
uv run pytest tests/test_fastapi_v1_dashboard.py -q

Results:

ruff format: 477 files left unchanged
ruff check: All checks passed
pnpm typecheck: vue-tsc --noEmit passed
tests/test_kb_import.py: 3 passed
tests/test_fastapi_v1_dashboard.py: 62 passed

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Add proper server-side pagination for the knowledge base dashboard lists so all knowledge bases and documents can be browsed reliably.

New Features:

  • Introduce paginated loading for the knowledge base list in the dashboard with total count support and page navigation.
  • Switch the knowledge base documents table to server-driven pagination, allowing navigation across all documents.

Bug Fixes:

  • Ensure the native knowledge base dashboard no longer stops at the first page and correctly reflects the current page after deletions.

Enhancements:

  • Return total item counts from knowledge base and document list service endpoints while preserving existing response structure.
  • Improve pagination behavior after deletions by automatically stepping back a page when the current page becomes empty.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. feature:knowledge-base The bug / feature is about knowledge base labels Jun 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Switching DocumentsTab.vue to v-data-table-server keeps the search prop but loadDocuments doesn’t send searchQuery to the backend, so the search now only applies to the current page instead of the full result set—consider either wiring the search term into the API call or reverting to client-side filtering semantics explicitly.
  • In knowledge_base_service.list_kbs, you call kb_manager.list_kbs() to get all KBs and then slice in Python; if the underlying manager can support pagination, consider pushing the page/page_size down to avoid loading the full list in memory for large deployments.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Switching `DocumentsTab.vue` to `v-data-table-server` keeps the `search` prop but `loadDocuments` doesn’t send `searchQuery` to the backend, so the search now only applies to the current page instead of the full result set—consider either wiring the search term into the API call or reverting to client-side filtering semantics explicitly.
- In `knowledge_base_service.list_kbs`, you call `kb_manager.list_kbs()` to get all KBs and then slice in Python; if the underlying manager can support pagination, consider pushing the `page`/`page_size` down to avoid loading the full list in memory for large deployments.

## Individual Comments

### Comment 1
<location path="dashboard/src/views/knowledge-base/components/DocumentsTab.vue" line_range="14-15" />
<code_context>
     <!-- 文档列表 -->
     <v-card variant="outlined">
-      <v-data-table :headers="headers" :items="documents" :loading="loading" :search="searchQuery" :items-per-page="10">
+      <v-data-table-server :headers="headers" :items="documents" :loading="loading" :search="searchQuery"
+        :items-per-page="pageSize" :page="page" :items-length="total"
+        @update:page="onPageChange" @update:items-per-page="onItemsPerPageChange">
         <template #item.doc_name="{ item }">
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `v-data-table-server` with the `search` prop likely disables the existing client-side search behavior.

With `v-data-table-server`, filtering is expected to be done on the server, so the `search` prop is typically ignored. Here `searchQuery` is still passed to the component, but `loadDocuments` never sends it to `knowledgeApi.documents`, so search will likely stop working. Either pass `searchQuery` to the API and reload on search changes, or revert to `v-data-table` if you need client-side filtering.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dashboard/src/views/knowledge-base/components/DocumentsTab.vue Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements server-side pagination for both the knowledge base list and the documents list. It updates the backend services to calculate pagination slices and return total counts, and modifies the frontend Vue components to use pagination controls and v-data-table-server. Feedback points out that switching to v-data-table-server in DocumentsTab.vue breaks the search functionality because the backend list_documents API does not support search, and search query changes are not properly handled via events. Additionally, in knowledge_base_service.py, negative or zero values for page or page_size could lead to incorrect slicing, so slicing indices should be guarded using max(1, ...).

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread dashboard/src/views/knowledge-base/components/DocumentsTab.vue Outdated
Comment thread astrbot/dashboard/services/knowledge_base_service.py
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. feature:knowledge-base The bug / feature is about knowledge base size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant