perf: group catalog source reads by identity
This commit was merged in pull request #40.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user