Skip to content

Commit

Permalink
fix: metrics performance patch (#4108)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus committed Jun 29, 2023
1 parent 65995b2 commit 19770fc
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/lib/services/client-metrics/metrics-service-v2.ts
Expand Up @@ -162,15 +162,19 @@ export default class ClientMetricsServiceV2 {
100,
);

const result = environments.flatMap((environment) =>
applications.flatMap((appName) =>
hours.flatMap((hourBucket) => {
const metric = metrics.find(
const result = environments.flatMap((environment) => {
const environmentMetrics = metrics.filter(
(metric) => metric.environment === environment,
);
return applications.flatMap((appName) => {
const applicationMetrics = environmentMetrics.filter(
(metric) => metric.appName === appName,
);
return hours.flatMap((hourBucket) => {
const metric = applicationMetrics.find(
(item) =>
compareAsc(hourBucket.timestamp, item.timestamp) ===
0 &&
item.appName === appName &&
item.environment === environment,
0,
);
return (
metric || {
Expand All @@ -182,10 +186,9 @@ export default class ClientMetricsServiceV2 {
featureName,
}
);
}),
),
);

});
});
});
return result.sort((a, b) => compareAsc(a.timestamp, b.timestamp));
}

Expand Down

0 comments on commit 19770fc

Please sign in to comment.