镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

improvement(perf): bound trash, file-path and attachment reads - #8945

Merged
waleedlatif1 merged 2 commits into
stagingfrom
perf/bounded-reads
Oct 12, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
perf/bounded-reads

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Recently Deleted reads one bounded page at a time. The settings page loaded every archived workflow, folder, table, knowledge base, file, file folder and chat in full (tables also ran a per-row size subquery and a jobs lookup) and then searched and sorted in memory. It now calls a new GET /api/workspaces/[id]/recently-deleted, which returns 50 rows per page with keyset pagination. Each type's query is limited to limit + 1 rows, in page order, using its (workspace_id, deleted) partial index. The query reads one UNION ALL of those per-type queries and only the columns the list renders. Search and sort run on the server and the UI scrolls infinitely. Ties still break name then id, A→Z, in either direction.
    • Authorization runs in a new application use case: workspace read, then each type's own list capability (a withheld capability hides that type and its folders), and chats only for the viewer's own.
    • Existing per-type endpoints, the v2 API and other UI are unchanged.
  • Copilot path lookups no longer list every workspace file. run_code file mounts and the file-preview target resolution now share one batched candidate query (findListedWorkspaceFiles, built on the display-name index candidate query) under the same files.list authorization. It keeps the listing's exact matching rules.
    • Directory mounts page the folder subtree in SQL and are capped at the mount limit.
  • Chat attachment reads no longer load the transcript. read_attachment reads only the fileAttachments entries whose id or filename matches, through the same lateral-array pattern as the MCP server lookup.
  • KeysetKey gains an optional fixed direction for ascending tiebreakers, and keysetOrderBy, so the trash reuses the shared keyset engine.
  • useLoadMoreSentinel is extracted from Resource and shared.

Type of Change

  • Improvement (performance)

Testing

  • New integration suites run in CI:
    • lib/workspaces/__integration__/recently-deleted.integration.ts: per-type predicates, page walks at limits 1/2/3 equal the unpaged order for every sort, microsecond page boundaries, search escaping, type narrowing, cursor validation.
    • lib/mothership/chat/file-attachments.integration.ts: equivalence with the transcript scan, malformed entries, deleted messages.
    • A new case in file-names.integration.ts checks that the batched and single lookups pick exactly the file the full listing picked.
  • Updated unit tests pass: read-attachment.test.ts, stream.test.ts, function-execute-file-mounts.test.ts, list-query*.test.ts, workspace-file-reference.test.ts, list-workspace-files.test.ts, folders/tables/mothership-chats hook tests.
  • These checks pass locally: biome on changed files, check:api-validation:strict, check:react-query, check:boundaries, check:client-boundary, check:utils, check:comment-hygiene, check:test-patterns, check:file-names, and the permission-group enforcement audit.
  • Not run locally, left to CI: full type-check, check:audits, and the integration suites. The UI has not been verified in a browser.

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 Oct 12, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Oct 12, 2026 10:02pm 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.

All reported issues were addressed across 33 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/workspaces/recently-deleted.ts Outdated
Comment thread apps/sim/hooks/queries/recently-deleted.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issue was found.

Summary

This PR bounds Recently Deleted pages, narrows workspace file lookups, and reads matching chat attachments instead of whole transcripts.

The latest changes:

  • Recently Deleted searches and sorts results on the server as you load more pages.
  • Copilot resolves file mounts without listing every workspace file.
  • Chat attachment reads fetch only entries that match the requested name.

Previous threads:

  • The chat ID mismatch is fixed.
  • The hook interface requirement is satisfied.
  • waleedlatif1 accepted the remaining chat-page sorting cost and deferred the index migration. They reported acceptable measured latency and wanted to avoid conflicting with a sibling migration PR.

No new actionable findings were accepted. Checks were limited to source review; no tests or browser checks were run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  UI[Recently Deleted] --> Route[Request one page]
  Route --> Access[Check workspace and resource access]
  Access --> Query[Combine bounded reads]
  Query --> Page[Rows and next cursor]
  Page --> UI
  UI --> Retry[Retry failed page]
  Retry --> Route
Loading

Reviews (2) · Last reviewed commit: "fix(recently-deleted): cast chat ids in ..." · Reviewed by Greptile

Comment thread apps/sim/lib/workspaces/recently-deleted.ts Outdated
Comment thread apps/sim/lib/workspaces/recently-deleted.ts
Comment thread apps/sim/hooks/use-load-more-sentinel.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@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.

All reported issues were addressed across 35 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/workspaces/recently-deleted.ts
@waleedlatif1
waleedlatif1 merged commit 1cdb8c1 into staging Oct 12, 2026
48 checks passed

This branch was successfully deployed

1 active deployment
Preview — 94289e9c Deployed Oct 12, 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