This commit is contained in:
@@ -140,7 +140,10 @@ export default function MigrationPage() {
|
|||||||
if (!toMigrate.length) return;
|
if (!toMigrate.length) return;
|
||||||
setMigrating(true);
|
setMigrating(true);
|
||||||
|
|
||||||
for (const file of toMigrate) {
|
// Process in batches of CONCURRENCY to upload multiple files in parallel
|
||||||
|
const CONCURRENCY = 5;
|
||||||
|
|
||||||
|
const migrateOne = async (file: FileEntry) => {
|
||||||
setStatuses((prev) => new Map(prev).set(file.key, "uploading"));
|
setStatuses((prev) => new Map(prev).set(file.key, "uploading"));
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/admin/migration", {
|
const res = await fetch("/api/admin/migration", {
|
||||||
@@ -151,7 +154,6 @@ export default function MigrationPage() {
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (!res.ok) throw new Error(data.error ?? "Upload failed");
|
if (!res.ok) throw new Error(data.error ?? "Upload failed");
|
||||||
setStatuses((prev) => new Map(prev).set(file.key, "done"));
|
setStatuses((prev) => new Map(prev).set(file.key, "done"));
|
||||||
// Mark as synced in the file list
|
|
||||||
setFiles((prev) =>
|
setFiles((prev) =>
|
||||||
prev.map((f) => (f.key === file.key ? { ...f, hetznerExists: true } : f))
|
prev.map((f) => (f.key === file.key ? { ...f, hetznerExists: true } : f))
|
||||||
);
|
);
|
||||||
@@ -161,6 +163,11 @@ export default function MigrationPage() {
|
|||||||
new Map(prev).set(file.key, e instanceof Error ? e.message : "Failed")
|
new Map(prev).set(file.key, e instanceof Error ? e.message : "Failed")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run in batches of CONCURRENCY
|
||||||
|
for (let i = 0; i < toMigrate.length; i += CONCURRENCY) {
|
||||||
|
await Promise.all(toMigrate.slice(i, i + CONCURRENCY).map(migrateOne));
|
||||||
}
|
}
|
||||||
|
|
||||||
setMigrating(false);
|
setMigrating(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user