mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-24 20:42:05 +03:00
Improve performance on findMany queries (#4334)
* Improve performance on findMany queries * Fix
This commit is contained in:
parent
b2210bd418
commit
e7857d7fa3
@ -69,6 +69,7 @@ export const useActivities = ({
|
||||
useFindManyRecords<Activity>({
|
||||
skip: skipActivities,
|
||||
objectNameSingular: CoreObjectNameSingular.Activity,
|
||||
depth: 3,
|
||||
filter,
|
||||
orderBy: activitiesOrderByVariables,
|
||||
onCompleted: useRecoilCallback(
|
||||
|
@ -10,17 +10,11 @@ export const useMapFieldMetadataToGraphQLQuery = () => {
|
||||
|
||||
const mapFieldMetadataToGraphQLQuery = ({
|
||||
field,
|
||||
maxDepthForRelations = 2,
|
||||
onlyTypenameAndIdOnDeepestRelationFields = false,
|
||||
depth = 2,
|
||||
}: {
|
||||
field: FieldMetadataItem;
|
||||
maxDepthForRelations?: number;
|
||||
onlyTypenameAndIdOnDeepestRelationFields?: boolean;
|
||||
depth?: number;
|
||||
}): any => {
|
||||
if (maxDepthForRelations <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// TODO: parse
|
||||
const fieldType = field.type as FieldType;
|
||||
|
||||
@ -50,26 +44,23 @@ export const useMapFieldMetadataToGraphQLQuery = () => {
|
||||
(field.toRelationMetadata as any)?.fromObjectMetadata?.id,
|
||||
);
|
||||
|
||||
let subfieldQuery = '';
|
||||
|
||||
if (maxDepthForRelations > 0) {
|
||||
subfieldQuery = `${(relationMetadataItem?.fields ?? [])
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: maxDepthForRelations - 1,
|
||||
onlyTypenameAndIdOnDeepestRelationFields,
|
||||
}),
|
||||
)
|
||||
.join('\n')}`;
|
||||
if (depth > 1) {
|
||||
return `${field.name}
|
||||
{
|
||||
__typename
|
||||
id
|
||||
${(relationMetadataItem?.fields ?? [])
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
depth: depth - 1,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
}`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `${field.name}
|
||||
{
|
||||
__typename
|
||||
id
|
||||
${subfieldQuery}
|
||||
}`;
|
||||
} else if (
|
||||
fieldType === 'RELATION' &&
|
||||
field.toRelationMetadata?.relationType === 'ONE_TO_ONE'
|
||||
@ -80,26 +71,23 @@ export const useMapFieldMetadataToGraphQLQuery = () => {
|
||||
(field.toRelationMetadata as any)?.fromObjectMetadata?.id,
|
||||
);
|
||||
|
||||
let subfieldQuery = '';
|
||||
|
||||
if (maxDepthForRelations > 0) {
|
||||
subfieldQuery = `${(relationMetadataItem?.fields ?? [])
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: maxDepthForRelations - 1,
|
||||
onlyTypenameAndIdOnDeepestRelationFields,
|
||||
}),
|
||||
)
|
||||
.join('\n')}`;
|
||||
if (depth > 1) {
|
||||
return `${field.name}
|
||||
{
|
||||
__typename
|
||||
id
|
||||
${(relationMetadataItem?.fields ?? [])
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
depth: depth - 1,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
}`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `${field.name}
|
||||
{
|
||||
__typename
|
||||
id
|
||||
${subfieldQuery}
|
||||
}`;
|
||||
} else if (
|
||||
fieldType === 'RELATION' &&
|
||||
field.fromRelationMetadata?.relationType === 'ONE_TO_MANY'
|
||||
@ -110,30 +98,27 @@ export const useMapFieldMetadataToGraphQLQuery = () => {
|
||||
(field.fromRelationMetadata as any)?.toObjectMetadata?.id,
|
||||
);
|
||||
|
||||
let subfieldQuery = '';
|
||||
|
||||
if (maxDepthForRelations > 0) {
|
||||
subfieldQuery = `${(relationMetadataItem?.fields ?? [])
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: maxDepthForRelations - 1,
|
||||
onlyTypenameAndIdOnDeepestRelationFields,
|
||||
}),
|
||||
)
|
||||
.join('\n')}`;
|
||||
}
|
||||
|
||||
return `${field.name}
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
id
|
||||
${subfieldQuery}
|
||||
if (depth > 1) {
|
||||
return `${field.name}
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
id
|
||||
${(relationMetadataItem?.fields ?? [])
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
depth: depth - 1,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
}`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else if (fieldType === 'LINK') {
|
||||
return `
|
||||
${field.name}
|
||||
|
@ -36,7 +36,7 @@ export const useAddRecordInCache = ({
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: MAX_QUERY_DEPTH_FOR_CACHE_INJECTION,
|
||||
depth: MAX_QUERY_DEPTH_FOR_CACHE_INJECTION,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
|
@ -29,7 +29,7 @@ export const useGenerateFindDuplicateRecordsQuery = () => {
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: depth,
|
||||
depth,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
|
@ -74,7 +74,7 @@ export const useGenerateFindManyRecordsForMultipleMetadataItemsQuery = ({
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: depth,
|
||||
depth,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
|
@ -31,7 +31,7 @@ export const useGenerateFindManyRecordsQuery = () => {
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: depth,
|
||||
depth,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
|
@ -28,7 +28,7 @@ export const useGenerateFindOneRecordQuery = () => {
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
field,
|
||||
maxDepthForRelations: depth,
|
||||
depth,
|
||||
}),
|
||||
)
|
||||
.join('\n')}
|
||||
|
@ -9,7 +9,8 @@
|
||||
"**/*.spec.tsx",
|
||||
"**/*.test.tsx",
|
||||
"jest.config.ts",
|
||||
"tsup.config.ts"
|
||||
"tsup.config.ts",
|
||||
"tsup.ui.index.tsx"
|
||||
],
|
||||
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
|
||||
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export * from './src/modules/ui/input/button/components/FloatingButtonGroup'
|
||||
export * from './src/modules/ui/input/button/components/FloatingIconButton'
|
||||
export * from './src/modules/ui/input/button/components/FloatingIconButtonGroup'
|
||||
export * from './src/modules/ui/input/button/components/LightButton'
|
||||
export * from '@/ui/navigation/link/components/ActionLink.tsx'
|
||||
export * from './src/modules/ui/navigation/link/components/ActionLink.tsx'
|
||||
export * from './src/modules/ui/input/button/components/LightIconButton'
|
||||
export * from './src/modules/ui/input/button/components/MainButton'
|
||||
export * from './src/modules/ui/input/button/components/RoundedIconButton'
|
||||
|
Loading…
Reference in New Issue
Block a user