Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: feat: add $id at schema definitions to improve rjsf performance #862

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions engine/schema/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,18 @@ function fileUniqueId(
return [btoa(fileUrl), fileUrl];
}

export const newSchemaBuilder = (initial: SchemaData): SchemaBuilder => {
export const newSchemaBuilder = (
initial: SchemaData,
revision: string,
): SchemaBuilder => {
return {
data: initial,
withBlockSchema(schema: BlockModule | EntrypointModule): SchemaBuilder {
if (isEntrypoint(schema)) {
return newSchemaBuilder({
...initial,
entrypoints: [...initial.entrypoints, schema],
});
}, revision);
}
// routes is always entrypoints
if (schema.blockType === "routes" && schema.inputSchema) {
Expand All @@ -192,12 +195,12 @@ export const newSchemaBuilder = (initial: SchemaData): SchemaBuilder => {
config: schema.inputSchema,
},
],
});
}, revision);
}
return newSchemaBuilder({
...initial,
blockModules: [...initial.blockModules, schema],
});
}, revision);
},
build() {
const schemeableId = (
Expand Down Expand Up @@ -366,8 +369,16 @@ export const newSchemaBuilder = (initial: SchemaData): SchemaBuilder => {
},
] as [Schemas["definitions"], JSONSchema7],
);

const finalDefsWith$id = Object.fromEntries(
Object.entries(finalDefs).map((entry, idx) => {
entry[1] = { ...entry[1], $id: `#/${idx}-${revision}` };
return entry;
}),
);

return {
definitions: finalDefs,
definitions: finalDefsWith$id,
root: {
...root,
entrypoint,
Expand Down
6 changes: 4 additions & 2 deletions engine/schema/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ const resolveImport = (path: string) => {

export const genSchemasFromManifest = async (
manifest: AppManifest,
baseDir?: string,
baseDir: string | undefined = undefined,
importMap: ImportMap = { imports: {} },
revision: Promise<string>,
): Promise<Schemas> => {
const { baseUrl: _ignore, name: _ignoreName, ...manifestBlocks } = manifest;
const dir = toFileUrl(baseDir ? baseDir : Deno.cwd()).toString();
Expand All @@ -82,11 +83,12 @@ export const genSchemasFromManifest = async (
},
{} as Record<string, JSONSchema7>,
);
const rev = await revision;
const schemaBuilder = newSchemaBuilder({
schema: { root: rootWithBlocks, definitions: {} },
blockModules: [],
entrypoints: [],
});
}, rev);

const refPromises: Promise<
(BlockModule | EntrypointModule | undefined)
Expand Down
6 changes: 5 additions & 1 deletion engine/schema/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ export const lazySchemaFor = (ctx: Omit<DecoContext, "schema">): LazySchema => {
const { manifest, importMap } = await ctx.runtime!;
_cached = incorporateSavedBlocksIntoSchema(
manifest,
await genSchemas(manifest, importMap),
await genSchemas(
manifest,
importMap,
ctx.release?.revision() ?? Promise.resolve(""),
),
{
...await ctx.release!.state(),
},
Expand Down
2 changes: 2 additions & 0 deletions engine/schema/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import type { AppManifest } from "../../types.ts";
export const genSchemas = async (
manifest: AppManifest,
importMap: ImportMap = { imports: {} },
revision: Promise<string>,
) => {
const base = Deno.cwd();
const schema = await genSchemasFromManifest(
manifest,
base,
importMap,
revision,
);

if (!context.isDeploy) {
Expand Down
Loading