perf(core): define bounded reference search
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user