Repository navigation
fix: Avoid quadratic relationship lookup in typescript generator - #1101
Merged
avallete merged 1 commit intoAug 11, 2026
Conversation
dcamachoc
marked this pull request as ready for review
August 11, 2026 11:46
avallete
approved these changes
Aug 11, 2026
avallete
deleted the
davidcamachocateura/api-1579-prevent-requests-to-generatorstypescript-from-overloading
branch
August 11, 2026 12:58
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Improves the performance of
/generators/typescriptendpointWhat is the current behavior?
getRelationshipsin the TypeScript type generator (src/server/templates/typescript.ts) is called once per table/view, and each call does a full linear scan (.filter()) over all relationships in the schema to find the ones belonging to that table. This makes the overall type-generation pass O(tables × relationships) — for schemas with many tables and foreign keys, this scales quadratically and can turn into a long-running, CPU-bound, synchronous operation for large schemas.Because this work runs synchronously on the Node.js event loop, a single request against a large enough schema could block the process entirely for its duration — delaying or timing out every other in-flight request until it finished. In effect, one expensive request was enough to make the whole service become unresponsive.
What is the new behavior?
getRelationshipsnow groups all relationships into aMapkeyed byschema.relationin a single upfront pass, and each table/view lookup becomes an O(1) map lookup instead of a full scan. This reduces the overall complexity from O(tables × relationships) to O(tables + relationships), with no change to the generated output.Additional context
No functional/output changes — the generated TypeScript types are identical; this is purely an algorithmic complexity fix aimed at reducing CPU usage and latency for large schemas, and preventing a single expensive request from stalling the rest of the service.