Fix featureFlag N+1 queries (#10261)

## Context
Regression was introduced 3 weeks ago when we added relations v2.
Because the relation logic is recursive during the life of a request, we
were querying the featureFlags many times.

We are now always using the featureFlag map and it's now available in
the base resolver so we don't need to query it everywhere, preferably
passing it as a parameter instead.

Note: We should introduce a cache for featureFlags in the future, this
is something easy to control and invalidate when needed.
This commit is contained in:
Weiko
2025-02-18 14:43:42 +01:00
committed by GitHub
parent ade13826c2
commit 0234c8d707
16 changed files with 78 additions and 91 deletions
@@ -83,13 +83,13 @@ export abstract class GraphqlQueryBaseResolverService<
await this.validate(args, options);
const permissionsEnabled = await this.featureFlagService.isFeatureEnabled(
FeatureFlagKey.IsPermissionsEnabled,
authContext.workspace.id,
);
const featureFlagsMap =
await this.featureFlagService.getWorkspaceFeatureFlagsMap(
authContext.workspace.id,
);
if (
permissionsEnabled === true &&
featureFlagsMap[FeatureFlagKey.IsPermissionsEnabled] &&
objectMetadataItemWithFieldMaps.isSystem === true
) {
await this.validateSystemObjectPermissions(options);
@@ -118,11 +118,6 @@ export abstract class GraphqlQueryBaseResolverService<
objectMetadataItemWithFieldMaps.nameSingular,
);
const featureFlagsMap =
await this.featureFlagService.getWorkspaceFeatureFlagsMap(
authContext.workspace.id,
);
const graphqlQueryParser = new GraphqlQueryParser(
objectMetadataItemWithFieldMaps.fieldsByName,
options.objectMetadataMaps,
@@ -146,7 +141,10 @@ export abstract class GraphqlQueryBaseResolverService<
graphqlQuerySelectedFieldsResult,
};
const results = await this.resolve(graphqlQueryResolverExecutionArgs);
const results = await this.resolve(
graphqlQueryResolverExecutionArgs,
featureFlagsMap,
);
const resultWithGetters = await this.queryResultGettersFactory.create(
results,
@@ -214,6 +212,7 @@ export abstract class GraphqlQueryBaseResolverService<
protected abstract resolve(
executionArgs: GraphqlQueryResolverExecutionArgs<Input>,
featureFlagsMap: Record<FeatureFlagKey, boolean>,
): Promise<Response>;
protected abstract validate(