Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PQueue to run only one create folder promise in folder upload #2210

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/files/src/components/UploadMenu.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<ul class="uk-list uk-margin-remove">
<li v-for="(item, index) in items" :key="item.name">
<li v-for="(item, index) in items" :key="item.id">
<div class="uk-flex">
<oc-icon name="file_copy" class="uk-margin-small-right" />
<div class="uk-width-expand">
Expand Down
15 changes: 12 additions & 3 deletions apps/files/src/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import moment from 'moment'
import FileUpload from './FileUpload.js'
import fileTypeIconMappings from './fileTypeIconMappings.json'
import { mapActions, mapGetters } from 'vuex'
const { default: PQueue } = require('p-queue')

export default {
filters: {
Expand All @@ -27,7 +28,9 @@ export default {
changeFileName: false,
fileToBeDeleted: '',
newName: '',
originalName: null
originalName: null,
queue: new PQueue({ concurrency: 1 }),
uploadFileUniqueId: 0
}),
computed: {
...mapGetters('Files', ['searchTerm', 'inProgress', 'files', 'selectedFiles', 'highlightedFile', 'activeFiles']),
Expand Down Expand Up @@ -328,11 +331,15 @@ export default {
const createFolderPromises = []
const rootDir = directoriesToCreate[0]
for (const directory of directoriesToCreate) {
let p

if (this.publicPage()) {
createFolderPromises.push(this.$client.publicFiles.createFolder(this.rootPath + directory))
p = this.queue.add(() => this.$client.publicFiles.createFolder(this.rootPath + directory))
} else {
createFolderPromises.push(this.$client.files.createFolder(this.rootPath + directory))
p = this.queue.add(() => this.$client.files.createFolder(this.rootPath + directory))
}

createFolderPromises.push(p)
}
// Upload files
const uploadPromises = []
Expand Down Expand Up @@ -361,6 +368,8 @@ export default {
})
},
$_ocUpload (file, path, overwrite = null, emitSuccess = true) {
file.id = this.uploadFileUniqueId
this.uploadFileUniqueId++
this.addFileToProgress(file)
const fileUpload = new FileUpload(file, path, this.url, this.headers, this.$_ocUpload_onProgress, this.requestType)
return fileUpload
Expand Down