Skip to content

Commit

Permalink
Change to immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Mar 15, 2022
1 parent 7a81024 commit 9f57ca3
Showing 1 changed file with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,30 @@ export const fetchSignificantCorrelations = async (
)
);

let fallbackResult: LatencyCorrelation | undefined;
const latencyCorrelations: LatencyCorrelation[] = [];

fulfilled.forEach((d: LatencyCorrelation | undefined) => {
if (d === undefined) return;
if (Array.isArray(d.histogram)) {
latencyCorrelations.push(d);
} else {
if (!fallbackResult) {
fallbackResult = d;
} else {
if (
d.ksTest > fallbackResult.ksTest &&
d.correlation > fallbackResult.correlation
) {
fallbackResult = d;
}
}
}
});

const latencyCorrelations: LatencyCorrelation[] = fulfilled.filter(
(d) => d && 'histogram' in d
);
let fallbackResult =
latencyCorrelations.length > 0
? undefined
: fulfilled
.filter((d) => !d?.histogram)
.reduce((d, result) => {
if (d?.correlation !== undefined) {
if (!result) {
result = d?.correlation > 0 ? d : undefined;
} else {
if (
d.correlation > 0 &&
d.ksTest > result.ksTest &&
d.correlation > result.correlation
) {
result = d;
}
}
}
return result;
}, undefined);
if (latencyCorrelations.length === 0 && fallbackResult) {
const { fieldName, fieldValue } = fallbackResult;
const logHistogram = await fetchTransactionDurationRanges(
Expand All @@ -107,9 +110,9 @@ export const fetchSignificantCorrelations = async (
[{ fieldName, fieldValue }]
);

if (typeof fallbackResult === 'object' && fallbackResult !== null) {
if (fallbackResult) {
fallbackResult = {
...(fallbackResult as LatencyCorrelation),
...fallbackResult,
histogram: logHistogram,
};
}
Expand Down

0 comments on commit 9f57ca3

Please sign in to comment.