Unverified Commit caabe013 authored by davelopez's avatar davelopez
Browse files

Submit remote files as single batch request per target history

This is unlikely to happen, but it will be consistent if we switch around histories and add remote files to different ones while pausing and continuing upload progress on them.
parent ada6e88d
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -111,19 +111,27 @@ export class UploadQueue {
        }
    }

    // Submit remote files as single batch request
    // Submit remote files as single batch request per target history
    _processUrls() {
        const list = [];
        const batchByHistory = {};
        for (const index of this.queue.keys()) {
            const model = this.opts.get(index);
            if (model.status === "queued" && model.fileMode === "url") {
                list.push({ index, ...model });
                if (!model.targetHistoryId) {
                    throw new Error(`Missing target history for upload item [${index}] ${model.fileName}`);
                }
                if (!batchByHistory[model.targetHistoryId]) {
                    batchByHistory[model.targetHistoryId] = [];
                }
                batchByHistory[model.targetHistoryId].push({ index, ...model });
                this.remove(index);
            }
        }
        if (list.length > 0) {

        for (const historyId in batchByHistory) {
            const list = batchByHistory[historyId];
            try {
                const data = uploadPayload(list, this.opts.historyId);
                const data = uploadPayload(list, historyId);
                sendPayload(data, {
                    success: (message) => {
                        list.forEach((model) => {