Repository navigation
fix(cli): a namespace section read loads the project once, not once per guide below it - #8504
Conversation
…er guide below it astryx docs <namespace> <section> read every guide below the namespace with resolveTopicDocs(guide.route), and each call loaded the project's docs catalog again, which also missed the per-catalog lowering memo. The namespace read already holds the catalog it loaded, so namespaceSection now reads every guide from it: resolveDocsArgument and resolveTopicDocs take an optional catalog. authoring has 49 guides below it, so a section read there loaded the project 50 times and now loads it once; docs-homes.test.mjs reads 19 sections through authoring and drops from about 19 s to about 2 s.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Thanks — reading every guide from the catalog the namespace read already loaded is a clean fix, and every namespace section answer stays the same, but one change is needed before this can merge. Because the catalog travels in the same options object the public docs() receives (packages/cli/api/docs/docs.mjs:152), callers can now set an undeclared catalog option: a builtins catalog hides a project's integration docs, and a value such as 'npm' throws a raw TypeError and then ends the process through an unhandled rejection. Please pass the loaded catalog as its own internal argument (for example resolveTopicDocs(guide.route, options, catalog)) and add a case showing docs() ignores a catalog key, since spec:AST-017 FR14 allows no undocumented caller-settable control. Optionally, the changeset's "tens of milliseconds" describes the in-process read better than the whole astryx docs authoring <section> command.
[Automated review]
| */ | ||
| export async function resolveDocsArgument(topic, {cwd} = {}) { | ||
| const catalog = await loadDocsCatalog(cwd); | ||
| export async function resolveDocsArgument(topic, {cwd, catalog: loaded} = {}) { |
There was a problem hiding this comment.
This reads catalog from the same options object the public docs() forwards (docs.mjs:152), so docs(topic, section, {catalog}) now skips the project load and reads whatever the caller passes: a builtins catalog hides the project's integration docs, and {catalog: 'npm'} throws a raw TypeError and then ends the process through an unhandled rejection in buildProjectTree. Taking the catalog as a separate internal argument, for example resolveDocsArgument(topic, {cwd} = {}, loaded), keeps it out of reach of public callers (spec:AST-017 FR14).
There was a problem hiding this comment.
This keeps the catalog out of every caller's reach: resolveDocsArgument(topic, {cwd} = {}, loaded) and resolveTopicDocs(topic, options = {}, loaded) now take the loaded catalog as a separate internal argument (afcaf2b). A new case in namespace-section.test.mjs passes {catalog: 'npm'} to docs() for a namespace section and a flat topic and gets the same answers as without it; on the previous head it threw the TypeError you described.
| '@astryxdesign/cli': patch | ||
| --- | ||
|
|
||
| [fix] `astryx docs <namespace> <section>` loads the project once instead of once for every guide below the namespace, so a section read on a namespace with many guides, such as `astryx docs authoring <section>`, answers in tens of milliseconds instead of most of a second. The answer is unchanged. |
There was a problem hiding this comment.
The read itself does drop to tens of milliseconds, but the whole astryx docs authoring <section> command still measured about 0.6 s end to end because start-up dominates; wording such as "the read itself takes tens of milliseconds instead of hundreds" would match what users see.
There was a problem hiding this comment.
The changeset now says what users see: "the read itself takes tens of milliseconds instead of hundreds" (afcaf2b).
…option resolveDocsArgument and resolveTopicDocs take the catalog a read already loaded as a separate third argument instead of an options field, so a caller of the public docs() cannot set it: a catalog key in docs() options is ignored and the read loads its own project (spec:AST-017 FR14). The changeset says the read itself, not the whole command, drops to tens of milliseconds.
There was a problem hiding this comment.
No further changes are needed: reading every guide from the catalog the namespace read already loaded makes astryx docs authoring <section> load the project once instead of 50 times, and every namespace section answer stays the same in English, dense and Chinese. The requested follow-up is in place, since the loaded catalog now travels as an internal argument and docs() ignores a catalog option exactly as before, which the new test pins.
[Automated review]
There was a problem hiding this comment.
Approved: reading every guide from the catalog the namespace read already loaded makes astryx docs authoring <section> load the project once instead of 50 times, and every namespace section answer stays the same in English, dense and Chinese.
The new load-count test fails without the fix and passes with it, and nothing else is needed from you.
[Automated review]
User impact
A section read on a docs namespace, such as
astryx docs authoring <section>, takes most of a second: it loads the project once per guide below the namespace. The same cost makesdocs-homes.test.mjstime out at its 60 s limit in a loaded full CLI run.Problem and solution fit
namespaceSectionread each guide withresolveTopicDocs(guide.route), and each of those calls loaded the docs catalog again (Project.load, thenproject.docs()).authoringhas 49 guides below it, so one section read there loaded the project 50 times.docs-homes.test.mjsreads all 19 field-reference sections throughauthoring, so that case took about 19 s on its own.Expected behavior and authority
spec:AST-046FR6: a namespace answers a section read from the one guide below it that has the section; that answer is unchanged. #7212 introduced these reads; the cost grew when #7835 moved the integration guides underauthoring.Smallest restoration
The namespace read already holds the catalog it loaded, because
resolveDocsArgumentreturns it.namespaceSectionnow takes that catalog and reads every guide from it;resolveDocsArgumentandresolveTopicDocsaccept an optionalcatalog. No output, API or test limit changes.Evidence
namespace-section.test.mjsspies onProject.loadduringdocs('authoring', <section>)and counts 50 calls on main.docs('authoring', key)reads take 6.9 s on main and 0.48 s with the fix (slowest read: 706 ms on main, 36 ms with the fix).toEqual), in English, dense and Chinese.Project.loadcount above fails as soon as a guide loads the project again.Scope
Testing
packages/cli/api/docs: 167 of 167 tests pass.packages/clisuite: 9,547 tests pass and 1 fails, a 30 s timeout inapi/search/_main-searcher.test.mjsat load 19. Run alone, it passes twice (6 of 6), and this change doesn't touch search.CI=true pnpm lint(0 errors),check:repoandcheck:changesetspass.