Skip to content

Commit c011898

Browse files
chore: add marks to reference variable resolution
1 parent 5785c66 commit c011898

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

apps/event-queue/src/release-targets/evaluate/variables/deployment-variable-provider.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class DeploymentVariableProvider implements VariableProvider {
2929
}
3030

3131
private async getRuleByReference(reference: string) {
32+
const now = performance.now();
3233
const allRelationshipRules =
3334
await this.workspace.repository.resourceRelationshipRuleRepository.getAll();
3435
const relationshipRule = allRelationshipRules.find(
@@ -54,6 +55,12 @@ export class DeploymentVariableProvider implements VariableProvider {
5455
const sourceMetadataEquals = allRelationshipRuleSourceMetadataEquals.filter(
5556
(r) => r.resourceRelationshipRuleId === relationshipRule.id,
5657
);
58+
59+
const end = performance.now();
60+
const duration = end - now;
61+
log.info(
62+
`Getting relationship rule by reference took ${duration.toFixed(2)}ms`,
63+
);
5764
return {
5865
...relationshipRule,
5966
metadataKeysMatch,
@@ -66,6 +73,7 @@ export class DeploymentVariableProvider implements VariableProvider {
6673
relationshipRule: schema.ResourceRelationshipRule,
6774
targetMetadataEqualsRules: schema.ResourceRelationshipRuleTargetMetadataEquals[],
6875
) {
76+
const now = performance.now();
6977
const { resource } = this.releaseTarget;
7078
const { targetKind, targetVersion } = relationshipRule;
7179
const targetKindSatisfied =
@@ -79,25 +87,34 @@ export class DeploymentVariableProvider implements VariableProvider {
7987
if (targetMetadata == null || targetMetadata !== t.value) return false;
8088
}
8189

90+
const end = performance.now();
91+
const duration = end - now;
92+
log.info(`Target resource matches rule took ${duration.toFixed(2)}ms`);
8293
return true;
8394
}
8495

8596
private async getSourceResourceCandidates(
8697
relationshipRule: schema.ResourceRelationshipRule,
8798
) {
99+
const now = performance.now();
88100
const { sourceKind, sourceVersion } = relationshipRule;
89101
const allResources =
90102
await this.workspace.repository.resourceRepository.getAll();
91-
return allResources.filter(
103+
const resources = allResources.filter(
92104
(r) =>
93105
r.kind === sourceKind &&
94106
r.version === sourceVersion &&
95107
r.deletedAt == null,
96108
);
109+
const end = performance.now();
110+
const duration = end - now;
111+
log.info(
112+
`Getting source resource candidates took ${duration.toFixed(2)}ms`,
113+
);
114+
return resources;
97115
}
98116

99117
private sourceResourceMatchesRule(
100-
relationshipRule: schema.ResourceRelationshipRule,
101118
sourceMetadataEqualsRules: schema.ResourceRelationshipRuleSourceMetadataEquals[],
102119
metadataKeysMatchRules: schema.ResourceRelationshipRuleMetadataMatch[],
103120
candidate: FullResource,
@@ -160,17 +177,27 @@ export class DeploymentVariableProvider implements VariableProvider {
160177
await this.getSourceResourceCandidates(relationshipRule);
161178
if (sourceResourceCandidates.length === 0) return defaultValue;
162179

180+
const sourceResourceSearchStart = performance.now();
163181
const sourceResource = sourceResourceCandidates.find((r) =>
164182
this.sourceResourceMatchesRule(
165-
relationshipRule,
166183
sourceMetadataEquals,
167184
metadataKeysMatch,
168185
r,
169186
),
170187
);
188+
const sourceResourceSearchEnd = performance.now();
189+
const sourceResourceSearchDuration =
190+
sourceResourceSearchEnd - sourceResourceSearchStart;
191+
log.info(
192+
`Source resource search took ${sourceResourceSearchDuration.toFixed(2)}ms`,
193+
);
171194
if (sourceResource == null) return defaultValue;
172195

196+
const fullSourceStart = performance.now();
173197
const fullSource = await this.getFullSource(sourceResource);
198+
const fullSourceEnd = performance.now();
199+
const fullSourceDuration = fullSourceEnd - fullSourceStart;
200+
log.info(`Full source retrieval took ${fullSourceDuration.toFixed(2)}ms`);
174201
const resolvedPath = _.get(fullSource, path, defaultValue);
175202
return resolvedPath as string | number | boolean | object | null;
176203
}

0 commit comments

Comments
 (0)