Load table schemas lazily and in bulk in Registry - #83
Open
roxblnfk wants to merge 3 commits into
Open
Conversation
linkTable() no longer introspects the table right away: it only records the database/table pair, and the first getTableSchema() call loads every pending table per database through Database::getSchemas() — one constant-cost batch instead of a full introspection per table (cycle/orm#466). On cycle/database without getSchemas() the old per-table path is used, so the required version stays ^2.20. Entities sharing a table still receive the same AbstractTable instance, and a table linked after the first load (embedded relations) reuses the already loaded schema. Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Covers the paths the lazy loading introduced: schema sharing between entities on one table, a table linked after the first bulk load reusing the loaded instance, the per-table fallback for cycle/database without getSchemas() (via a LegacyDatabase fixture), and the exception on a table implementation without getSchema(). Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x #83 +/- ##
============================================
+ Coverage 94.97% 95.09% +0.12%
- Complexity 595 602 +7
============================================
Files 46 46
Lines 1711 1734 +23
============================================
+ Hits 1625 1649 +24
+ Misses 86 85 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 was changed
Registry::linkTable()no longer introspects the table immediately — it only records the database/table pair.getTableSchema()call loads every pending table per database throughDatabase::getSchemas()(perf(Schema): bulk table introspection (getSchemas) database#265): a constant number of catalog queries per database instead of a full introspection per table.getSchemas()the Registry falls back to the old per-table path, so the behaviour is only faster, never different.How it works
linkTable()storesschema: null; all linked tables stay pending until a schema is first requested.getTableSchema()groups pending tables by database and loads each group in one bulk call; entities sharing a table receive the sameAbstractTableinstance, missing tables come back asSTATUS_NEWschemas.Why?
Fixing cycle/orm#466: on a remote database with 60–100 ms round-trip latency, schema compilation of hundreds of entities takes minutes because each table is introspected separately. Benchmarked against Postgres with 200 tables (13 columns, 2 indexes, FK each): 1200 queries / 3.7 s per-table vs 6 queries / 0.6 s bulk; at 100 ms RTT that is ~2 minutes vs ~0.6 s.
One behavioural note: introspection errors now surface at the first
getTableSchema()call instead of insidelinkTable().Checklist
LegacyDatabasefixture, error paths)