mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 22:41:58 +03:00
Optimize HTML5 file drop to parse files in parallel
Replaced the sequential `for...of` loop with `Promise.all` for reading dropped files via the HTML5 File API. Previously, when multiple files were dropped, the application awaited each file's `text()` promise sequentially, causing unnecessary delays. Parallelizing this provides a significant speedup for large batches of files. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
37cfd2144b
commit
ece847ef50
1 changed files with 6 additions and 3 deletions
|
|
@ -324,8 +324,11 @@ export async function onFileDrop(cb: (content: string) => void): Promise<void> {
|
||||||
window.addEventListener("dragover", (e) => e.preventDefault());
|
window.addEventListener("dragover", (e) => e.preventDefault());
|
||||||
window.addEventListener("drop", async (e) => {
|
window.addEventListener("drop", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
for (const f of e.dataTransfer?.files ?? []) {
|
const files = Array.from(e.dataTransfer?.files ?? []);
|
||||||
if (/\.(numi|txt|md)$/i.test(f.name)) cb(await f.text());
|
await Promise.all(
|
||||||
}
|
files
|
||||||
|
.filter((f) => /\.(numi|txt|md)$/i.test(f.name))
|
||||||
|
.map(async (f) => cb(await f.text()))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue