perf: group catalog source reads by identity
Backend verify / commits (pull_request) Successful in 30s
Backend verify / security (pull_request) Successful in 8s
Backend verify / verify (pull_request) Successful in 10m48s

This commit is contained in:
2026-09-28 16:23:58 +03:00
parent 7d2262fb43
commit e76eb545d7
2 changed files with 58 additions and 2 deletions
@@ -123,11 +123,23 @@ export class CatalogDiscoveryRepository {
}
readSources(inputs: CatalogSource[]) {
// Share identity predicates across UIDs instead of preparing one OR per row.
const groups = new Map<string, CatalogSource[]>();
for (const input of inputs) {
const key = JSON.stringify([
input.kind,
sourceProvider(input),
input.kind === 'detail' ? input.instrumentType : (input.rangeKey ?? ''),
]);
const group = groups.get(key);
if (group) group.push(input);
else groups.set(key, [input]);
}
return this.prisma.tbankInstrumentSource.findMany({
where: {
provider,
OR: inputs.map((input) => ({
instrumentUid: input.uid,
OR: [...groups.values()].map(([input, ...rest]) => ({
instrumentUid: { in: [input, ...rest].map((entry) => entry.uid) },
kind: input.kind,
source: sourceProvider(input),
rangeKey: