Skip to content

Commit b644010

Browse files
NicolappsConvex, Inc.
authored andcommitted
Memoise computation of useSingleTableSchemaStatus (#41610)
GitOrigin-RevId: 9bd40797a6614f29bc19437adc874b1b738d7d45
1 parent 73d860a commit b644010

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

npm-packages/dashboard-common/.eslintrc.cjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const path = require("path");
2-
31
module.exports = {
42
root: true,
53
parserOptions: {

npm-packages/dashboard-common/src/features/data/components/TableSchema.tsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,34 @@ export function useSingleTableSchemaStatus(
7676
const schemas = useQuery(udfs.getSchemas.default, {
7777
componentId: useNents().selectedNent?.id ?? null,
7878
});
79-
if (!schemas) {
80-
return undefined;
81-
}
82-
const active: Schema | undefined = schemas.active
83-
? JSON.parse(schemas.active)
79+
80+
const { isDefined, referencedByTable } = useMemo(() => {
81+
const active: Schema | undefined = schemas?.active
82+
? JSON.parse(schemas.active)
83+
: undefined;
84+
85+
return {
86+
isDefined:
87+
active?.tables.find((table) => table.tableName === tableName) !==
88+
undefined,
89+
referencedByTable: active?.tables.find((table) =>
90+
validatorReferencesTable(
91+
table.documentType ?? { type: "any" },
92+
tableName,
93+
),
94+
)?.tableName,
95+
};
96+
}, [schemas?.active, tableName]);
97+
98+
const isValidationRunning = schemas?.inProgress !== undefined;
99+
return schemas
100+
? {
101+
tableName,
102+
isDefined,
103+
referencedByTable,
104+
isValidationRunning,
105+
}
84106
: undefined;
85-
const isDefined =
86-
active?.tables.find((table) => table.tableName === tableName) !== undefined;
87-
const referencedByTable = active?.tables.find((table) =>
88-
validatorReferencesTable(table.documentType ?? { type: "any" }, tableName),
89-
)?.tableName;
90-
const isValidationRunning = schemas.inProgress !== undefined;
91-
return {
92-
tableName,
93-
isDefined,
94-
referencedByTable,
95-
isValidationRunning,
96-
};
97107
}
98108

99109
export function useSingleTableEnforcedSchema(tableName: string): Table | null {

0 commit comments

Comments
 (0)