Преглед на файлове

perf(admin): implement parallel file uploads in handleAttachFiles

unknown преди 3 месеца
родител
ревизия
9f87cfff7e
променени са 1 файла, в които са добавени 7 реда и са изтрити 6 реда
  1. 7 6
      src/pages/Admin.vue

+ 7 - 6
src/pages/Admin.vue

@@ -582,20 +582,21 @@ const handleAttachFiles = async (orderId: number, files: FileList | File | null)
   const id = orderId;
   const fileArray = files instanceof FileList ? Array.from(files) : [files];
   
-  const toastId = toast.loading(`Attaching ${fileArray.length} file(s)...`);
+  const toastId = toast.loading(`Uploading ${fileArray.length} file(s)...`);
 
   try {
-    for (const file of fileArray) {
-      console.log(`DEBUG: Uploading file: ${file.name} to order: ${id}`);
+    // Perform parallel uploads for speed
+    await Promise.all(fileArray.map(async (file) => {
+      console.log(`DEBUG: Starting upload for: ${file.name} to order: ${id}`);
       const fd = new FormData();
       fd.append("file", file);
-      await adminAttachFile(id, fd);
-    }
+      return adminAttachFile(id, fd);
+    }));
     
     toast.success(`${fileArray.length} file(s) attached successfully`, { id: toastId });
     await fetchData();
     
-    // Re-sync editingOrder if open
+    // Re-sync editingOrder if open to show new files immediately
     if (editingOrder.value?.id === id) {
       const updatedOrder = orders.value.find(o => o.id === id);
       if (updatedOrder) editingOrder.value = updatedOrder;