Skip to content

Commit

Permalink
Add concurrency limit when loading previews
Browse files Browse the repository at this point in the history
Added P-Queue to limit the number of concurrent requests related to the
media source when loading previews.

This will prevent such calls to block other operations like uploads.
  • Loading branch information
Vincent Petry committed Mar 23, 2020
1 parent d8b5ee1 commit cc77caf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"owncloud-design-system": "^1.1.1",
"owncloud-sdk": "^1.0.0-523",
"p-limit": "^2.2.1",
"p-queue": "^6.1.1",
"parse-json": "^5.0.0",
"path": "^0.12.7",
"requirejs": "^2.3.6",
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/mediaSource.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import store from '../store'
const { default: PQueue } = require('p-queue')

export default {
install (Vue) {
Expand Down Expand Up @@ -44,9 +45,14 @@ export default {
})

Vue.mixin({
data: function () {
return {
mediaSourceQueue: new PQueue({ concurrency: 2 })
}
},
methods: {
mediaSource (source, returnAs = 'url', headers = null) {
return _mediaSource(source, returnAs, headers)
return this.mediaSourceQueue.add(() => _mediaSource(source, returnAs, headers))
}
}
})
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6824,13 +6824,28 @@ p-map@^3.0.0:
dependencies:
aggregate-error "^3.0.0"

p-queue@^6.1.1:
version "6.3.0"
resolved "https://registry.yarnpkg.com/p-queue/-/p-queue-6.3.0.tgz#19bfa4485db7e6a0c135049ff6716375880d9c3a"
integrity sha512-fg5dJlFpd5+3CgG3/0ogpVZUeJbjiyXFg0nu53hrOYsybqSiDyxyOpad0Rm6tAiGjgztAwkyvhlYHC53OiAJOA==
dependencies:
eventemitter3 "^4.0.0"
p-timeout "^3.1.0"

p-retry@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/p-retry/-/p-retry-3.0.1.tgz#316b4c8893e2c8dc1cfa891f406c4b422bebf328"
integrity sha512-XE6G4+YTTkT2a0UWb2kjZe8xNwf8bIbnqpc/IS/idOBVhyves0mK5OJgeocjx7q5pvX/6m23xuzVPYT1uGM73w==
dependencies:
retry "^0.12.0"

p-timeout@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-3.2.0.tgz#c7e17abc971d2a7962ef83626b35d635acf23dfe"
integrity sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==
dependencies:
p-finally "^1.0.0"

p-try@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
Expand Down

0 comments on commit cc77caf

Please sign in to comment.