perf(core): define bounded reference search

This commit is contained in:
2026-07-30 01:29:45 +02:00
parent af3e0a055d
commit f3b388fe7e
5 changed files with 268 additions and 28 deletions

View File

@@ -53,8 +53,26 @@ export function apiReferenceOptionProvider(
return {
search: (query, context) =>
load(query, context.selectedValues, context.limit, context.signal),
resolve: (values, context) =>
load("", values, context.limit ?? values.length, context.signal)
async resolve(values, context) {
const uniqueValues = [...new Set(values.map((value) => value.trim()).filter(Boolean))];
const chunks: string[][] = [];
for (let index = 0; index < uniqueValues.length; index += 200) {
chunks.push(uniqueValues.slice(index, index + 200));
}
const pages = await Promise.all(
chunks.map((chunk) =>
load("", chunk, Math.min(200, Math.max(1, chunk.length)), context.signal)
)
);
const byValue = new Map(
pages.flat().map((option) => [option.value, option])
);
return uniqueValues.map(
(value) =>
byValue.get(value)
?? unavailableReferenceOption(value)
);
}
};
}