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

Implement eager load relations on graphqlQueries #4391

Merged
merged 4 commits into from
Mar 10, 2024

Conversation

charlesBochet
Copy link
Member

@charlesBochet charlesBochet commented Mar 10, 2024

In this PR, I'm refactoring the way graphql queries are built from objectMetadata in the different hooks:

  • useGenerateFindOneRecordQuery
  • useGenerateFindManyRecordQuery
  • ...

All these hooks were querying useMapFieldMetadataToGraphQLQuery

  1. converting useMapFieldMetadataToGraphQLQuery hook to an utils mapFieldMetadataToGraphQLQuery to avoid nesting loop loading of objectMetadataItems (~30us x 200 = 6ms) for a classic object with nesting 2.

  2. introducing mapObjectMetadataToGraphQLQuery to refactor mapping over object that was implemented ~10 times into one place

  3. introducing shouldFieldBeQueried

  4. introducing the possibility to query only a selected number of relations / fields
    ex:

const res = mapFieldMetadataToGraphQLQuery({
      objectMetadataItems: mockObjectMetadataItems,
      relationFieldDepth: 2,
      relationFieldEagerLoad: { accountOwner: true, people: true },
      field: CompanyFieldMetadataItem
    });

This can be nested as far as we want

  1. Adding tests

  2. Fine tuning depths in the code base to lower the calls

Next steps:

  • on Tasks Page, load all activityTargets at once (there are many many calls being performed currenty)
  • on Index Pages, only include the relations that are needed in the table / board based on ViewFields
  • (also double check what's happening to an exisitng object in the cache, when make a new graphql query without some relations. we should keep the information we already have)

@charlesBochet charlesBochet merged commit ec384cc into main Mar 10, 2024
15 checks passed
@charlesBochet charlesBochet deleted the eager-load-relations branch March 10, 2024 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant