Skip to content

Commit

Permalink
Merge pull request galaxyproject#18703 from davelopez/24.1_fix_upload…
Browse files Browse the repository at this point in the history
…_start

[24.1] Fix upload when current history changes
  • Loading branch information
mvdbeek authored Aug 15, 2024
2 parents ba3ff2c + 5e5e6fc commit ea35ee5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
11 changes: 7 additions & 4 deletions client/src/components/Upload/DefaultBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const props = defineProps({
},
lazyLoad: {
type: Number,
default: 50,
default: 150,
},
listDbKeys: {
type: Array,
Expand All @@ -84,6 +84,7 @@ const uploadCompleted = ref(0);
const uploadFile = ref(null);
const uploadItems = ref({});
const uploadSize = ref(0);
const queue = ref(createUploadQueue());
const counterNonRunning = computed(() => counterAnnounce.value + counterSuccess.value + counterError.value);
const enableBuild = computed(
Expand All @@ -99,16 +100,13 @@ const listExtensions = computed(() => props.effectiveExtensions.filter((ext) =>
const showHelper = computed(() => Object.keys(uploadItems.value).length === 0);
const uploadValues = computed(() => Object.values(uploadItems.value));
const queue = computed(() => createUploadQueue());
function createUploadQueue() {
return new UploadQueue({
announce: eventAnnounce,
chunkSize: props.chunkUploadSize,
complete: eventComplete,
error: eventError,
get: (index) => uploadItems.value[index],
historyId: historyId.value,
multiple: props.multiple,
progress: eventProgress,
success: eventSuccess,
Expand Down Expand Up @@ -268,6 +266,11 @@ function eventStart() {
uploadValues.value.forEach((model) => {
if (model.status === "init") {
model.status = "queued";
if (!model.targetHistoryId) {
// Associate with current history once upload starts
// This will not change if the current history is changed during upload
model.targetHistoryId = historyId.value;
}
uploadSize.value += model.fileSize;
}
});
Expand Down
15 changes: 10 additions & 5 deletions client/src/components/Upload/UploadModal.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<script setup>
import { setIframeEvents } from "components/Upload/utils";
import { useConfig } from "composables/config";
import { useUserHistories } from "composables/userHistories";
import { storeToRefs } from "pinia";
import { ref, watch } from "vue";
import { setIframeEvents } from "@/components/Upload/utils";
import { useConfig } from "@/composables/config";
import { useUserHistories } from "@/composables/userHistories";
import { useUserStore } from "@/stores/userStore";
import { wait } from "@/utils/utils";
import UploadContainer from "./UploadContainer.vue";
const { currentUser } = storeToRefs(useUserStore());
const { currentHistoryId } = useUserHistories(currentUser);
const { currentHistoryId, currentHistory } = useUserHistories(currentUser);
const { config, isConfigLoaded } = useConfig();
Expand Down Expand Up @@ -81,7 +81,12 @@ defineExpose({
no-enforce-focus
hide-footer>
<template v-slot:modal-header>
<h2 class="title h-sm" tabindex="0">{{ options.title }}</h2>
<h2 class="title h-sm" tabindex="0">
{{ options.title }}
<span v-if="currentHistory">
to <b>{{ currentHistory.name }}</b>
</span>
</h2>
</template>
<UploadContainer
v-if="currentHistoryId"
Expand Down
6 changes: 5 additions & 1 deletion client/src/composables/userHistories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export function useUserHistories(user) {
);

const currentHistoryId = computed(() => historyStore.currentHistoryId);
const currentHistory = computed(() => historyStore.currentHistory);

return { currentHistoryId };
return {
currentHistoryId,
currentHistory,
};
}
24 changes: 18 additions & 6 deletions client/src/utils/upload-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ export class UploadQueue {
// Remove item from queue
this.remove(index);
// Collect upload request data
const data = uploadPayload([this.opts.get(index)], this.opts.historyId);
const item = this.opts.get(index);
if (!item.targetHistoryId) {
throw new Error(`Missing target history for upload item [${index}] ${item.fileName}`);
}
const data = uploadPayload([item], item.targetHistoryId);
// Initiate upload request
this._processSubmit(index, data);
} catch (e) {
Expand All @@ -107,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) => {
Expand Down
1 change: 1 addition & 0 deletions client/src/utils/upload-queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ describe("UploadQueue", () => {
spaceToTab: true,
status: "queued",
toPosixLines: false,
targetHistoryId: "historyId",
};
},
get: (index) => fileEntries[index],
Expand Down

0 comments on commit ea35ee5

Please sign in to comment.