Skip to content

Commit a48d4ee

Browse files
committed
fix: frontend sequential uploads
1 parent c55af08 commit a48d4ee

1 file changed

Lines changed: 55 additions & 59 deletions

File tree

resources/js/Shared/FileSystemBrowser.vue

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ export default {
751751
showErrorBatchLogs: false,
752752
showLogsDialog: false,
753753
currentLog: null,
754+
sequentialProcessing: true, // Enable sequential processing to avoid race conditions
754755
fsoBeingDeleted: null,
755756
showMissingFilesDetails: null,
756757
missing_files: 0,
@@ -1291,7 +1292,7 @@ export default {
12911292
);
12921293
}
12931294
},
1294-
processFilesDZL(vm, filesBatch) {
1295+
async processFilesDZL(vm, filesBatch) {
12951296
vm.batchesCount += 1;
12961297
const url = "/dashboard/storage/signed-draft-storage-url";
12971298
const client = axios.create({ baseURL: window.location.origin });
@@ -1319,60 +1320,45 @@ export default {
13191320
);
13201321
},
13211322
});
1322-
client
1323+
1324+
return client
13231325
.post(url, {
13241326
draft_files: filesWithChecksums,
13251327
destination: vm.$page.props.selectedFolder,
13261328
draft_id: vm.draft.id,
13271329
})
13281330
.catch((err) => {
1329-
this.processedBatches += 1;
1330-
if (this.processedBatches == this.batches) {
1331-
if (this.dropzone.files.length > 0) {
1332-
this.status = "ERROR UPLOADING FILES";
1333-
this.updateBusyStatus(false);
1334-
this.dropzone.files.forEach((file) => {
1335-
let message = "Upload failed";
1336-
if (file.fullPath) {
1337-
vm.logs[file.fullPath].status = "Error";
1338-
vm.logs[file.fullPath].messages.push(
1339-
message +
1340-
" (API call failed with status code:" +
1341-
err.response.status +
1342-
") "
1343-
);
1344-
} else {
1345-
vm.logs[file.name].status = "Error";
1346-
vm.logs[file.name].messages.push(
1347-
message +
1348-
"(API call failed with status code:" +
1349-
err.response.status +
1350-
")"
1351-
);
1352-
}
1353-
});
1331+
// Log errors for the current batch
1332+
filesBatch.forEach((file) => {
1333+
let message = "Upload failed";
1334+
if (file.fullPath) {
1335+
vm.logs[file.fullPath].status = "Error";
1336+
vm.logs[file.fullPath].messages.push(
1337+
message +
1338+
" (API call failed with status code:" +
1339+
(err.response?.status || 'unknown') +
1340+
") "
1341+
);
1342+
} else {
1343+
vm.logs[file.name].status = "Error";
1344+
vm.logs[file.name].messages.push(
1345+
message +
1346+
"(API call failed with status code:" +
1347+
(err.response?.status || 'unknown') +
1348+
")"
1349+
);
13541350
}
1355-
}
1356-
this.uploadBatchErrors.push(err.response.data);
1357-
// console.log(
1358-
// "Error retrieving signed storage URLS",
1359-
// err.response
1360-
// );
1361-
// if (
1362-
// err.response.status !== 200 ||
1363-
// err.response.status !== 201
1364-
// ) {
1365-
// throw new Error(
1366-
// `API call failed with status code: ${err.response.status}`
1367-
// );
1368-
// }
1351+
});
1352+
1353+
this.uploadBatchErrors.push(err.response?.data || err.message);
1354+
throw err; // Re-throw to be caught by sequential processor
13691355
})
13701356
.then((response) => {
13711357
if (response) {
13721358
vm.currentLog =
13731359
"Uploading files to temporary storage url";
13741360
let data = response.data;
1375-
this.processedBatches += 1;
1361+
13761362
data.forEach((u) => {
13771363
let cFile = vm.dropzone.files.find((f) => {
13781364
if (f.fullPath) {
@@ -1411,15 +1397,40 @@ export default {
14111397
);
14121398
}
14131399
});
1400+
1401+
return response;
14141402
}
14151403
});
14161404
},
1405+
async processFilesSequentially(vm) {
1406+
try {
1407+
// Process files in sequential batches to avoid race conditions
1408+
for (let i = 0; i < vm.totalFilesCount; i += vm.batchCount) {
1409+
let filesBatch = vm.dropzone.files.slice(i, i + vm.batchCount);
1410+
vm.batches += 1;
1411+
1412+
vm.status = `PROCESSING BATCH ${vm.batches} OF ${Math.ceil(vm.totalFilesCount / vm.batchCount)}`;
1413+
1414+
// Wait for each batch to complete before processing the next
1415+
await vm.processFilesDZL(vm, filesBatch);
1416+
1417+
// Small delay between batches to prevent overwhelming the server
1418+
await new Promise(resolve => setTimeout(resolve, 100));
1419+
}
1420+
1421+
vm.status = "ALL BATCHES PROCESSED";
1422+
} catch (error) {
1423+
console.error("Error in sequential file processing:", error);
1424+
vm.status = "ERROR IN BATCH PROCESSING";
1425+
vm.updateBusyStatus(false);
1426+
}
1427+
},
14171428
loadDropZone() {
14181429
this.$nextTick(() => {
14191430
const vm = this;
14201431
vm.totalFilesCount = 0;
14211432
vm.uploadedFilesCount = 0;
1422-
vm.batchCount = 100;
1433+
vm.batchCount = 10; // Reduced batch size for sequential processing
14231434
vm.count = 0;
14241435
vm.batches = 0;
14251436
vm.processedBatches = 0;
@@ -1554,22 +1565,7 @@ export default {
15541565
) {
15551566
clearInterval(timer);
15561567
vm.status = "BATCH UPLOAD STARTED";
1557-
for (
1558-
let i = 0;
1559-
i < vm.totalFilesCount;
1560-
i += vm.batchCount
1561-
) {
1562-
let filesBatch =
1563-
vm.dropzone.files.slice(
1564-
i,
1565-
i + vm.batchCount
1566-
);
1567-
vm.batches += 1;
1568-
vm.processFilesDZL(
1569-
vm,
1570-
filesBatch
1571-
);
1572-
}
1568+
vm.processFilesSequentially(vm);
15731569
} else {
15741570
vm.totalFilesCount =
15751571
vm.selectedFSO.length;

0 commit comments

Comments
 (0)