Skip to content

fix(knowledge,files): per-base kb counts and a modified-order file index - #10026

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/kb-count-files-updated-index
Nov 14, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/kb-count-files-updated-index

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The knowledge base list's document count runs as one statement that counts each base on its own (knowledge_base CROSS JOIN LATERAL), instead of one grouped scan over every listed base. With many bases, the grouped form let the planner over-estimate their documents and AND the base index with bitmaps of every tenant's documents (the shared ws ACL token index and a partial index of unarchived documents) before reading a row. Listing many archived bases with no live documents took seconds warm and close to a minute cold. Measured against real data, the same counts went 4.2s → 0.22s, 1.0s → 0.12s for a mid-size workspace, and stayed level for a single very large base
  • The list and its live-source supplement now share one base filter: the list's own where when unpaged, the page's IDs otherwise
  • Adds workspace_files_workspace_active_updated_idx (workspace_id, updated_at, id, same predicate as 0442's upload-order index). Sorting by last modified is the file browser's default, and no index served it, so every list read and sorted all of the workspace's live files. Built concurrently, with 0442's replay-safe recovery
  • The database.mock aggregates (count, sum, …) get .as(alias) like drizzle's, which drops a test-local workaround in weekly-refresh.test.ts and shrinks the test-types baseline by one

Type of Change

  • Bug fix

Testing

  • knowledge-base-list.integration.ts: new case that lists many archived bases and asserts each index read of document seeks a single base and nothing seq-scans document. It fails on the pre-fix grouped count (the scan is knowledge_base_id = ANY(...)) and passes after
  • file-listing.integration.ts: new case asserting the whole-workspace updatedAt desc page reads workspace_files_workspace_active_updated_idx with sorting disabled. It fails without the index and passes with it
  • Also ran against real Postgres: workspace-kb-document-access, knowledge-projection, search-index-policy, content-delivery, file-list integration suites, plus service.test.ts and weekly-refresh.test.ts
  • check:migrations, drizzle-kit generate (no drift), migration applied to a fresh database, check:test-types, lint, block-registry check
  • Write cost: indexing updated_at means an update that only bumps it can no longer be heap-only. The edits that already touch an indexed column (name, folder, deletion) lose nothing

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Building Building Preview Nov 14, 2026 1:26am UTC

Request Review

@cubic-dev-ai cubic-dev-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.

No issues found across 12 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

This PR counts readable documents one knowledge base at a time and adds an index for files sorted by last modified.

  • Knowledge-base lists count each base's documents separately.
  • Workspace file pages use an index for modified-time order.
  • Aggregate mocks can now use aliases like the database library.

Reviews (1) · Last reviewed commit: "fix(knowledge,files): count knowledge ba..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit edb7799 into staging Nov 14, 2026
63 of 64 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/kb-count-files-updated-index branch November 14, 2026 01:30

This branch was successfully deployed

1 active deployment
Preview — 91fdcbbb Deployed Nov 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant