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