Skip to content

Reduce dots() N+1 queries to a single batch fetch - #146

Open
OpenGithubs wants to merge 1 commit into
CopilotKit:mainfrom
OpenGithubs:perf-dots-join
Open

OpenGithubs wants to merge 1 commit into
CopilotKit:mainfrom
OpenGithubs:perf-dots-join

Conversation

@OpenGithubs

Copy link
Copy Markdown

Summary

Performance optimization: WorkspaceStore.dots() used an N+1 query pattern — one SELECT * FROM dots followed by one SELECT spaceId FROM dot_spaces WHERE dotId=? per dot. With N dots that is N+1 database round-trips just to list the workspace. Now fetches all dot_spaces rows once and groups them in memory with a Map.

Changes

  • src/server/workspace.ts: batch fetch dot_spaces, group in-memory, cut N+1 round-trips down to 2.

Commits

  • perf-dots-join perf: reduce dots() N+1 queries to a single batch fetch

Previously dots() issued one dot_spaces SELECT per dot (N+1 pattern).
Now fetches all dot_spaces rows once and groups them in memory via a Map.
With 10 dots this cuts 11 DB round-trips down to 2.
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