mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-23 03:49:49 +00:00
Use RateLimiter instead of waiting for each attachment to load sequentially (#7546)
Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
This commit is contained in:
parent
84020b3305
commit
faac57091c
@ -14,7 +14,7 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { Attachment } from '@hcengineering/attachment'
|
||||
import { Account, Class, Doc, IdMap, Markup, Ref, Space, generateId, toIdMap } from '@hcengineering/core'
|
||||
import { RateLimiter, Account, Class, Doc, IdMap, Markup, Ref, Space, generateId, toIdMap } from '@hcengineering/core'
|
||||
import { Asset, IntlString, setPlatformStatus, unknownError } from '@hcengineering/platform'
|
||||
import {
|
||||
DraftController,
|
||||
@ -183,12 +183,14 @@
|
||||
await tick()
|
||||
const list = inputFile.files
|
||||
if (list === null || list.length === 0) return
|
||||
const limiter = new RateLimiter(10)
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
const file = list.item(index)
|
||||
if (file !== null) {
|
||||
await createAttachment(file)
|
||||
await limiter.add(() => createAttachment(file))
|
||||
}
|
||||
}
|
||||
await limiter.waitProcessing()
|
||||
inputFile.value = ''
|
||||
progress = false
|
||||
}
|
||||
@ -196,13 +198,16 @@
|
||||
async function fileDrop (e: DragEvent): Promise<void> {
|
||||
progress = true
|
||||
const list = e.dataTransfer?.files
|
||||
const limiter = new RateLimiter(10)
|
||||
|
||||
if (list === undefined || list.length === 0) return
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
const file = list.item(index)
|
||||
if (file !== null) {
|
||||
await createAttachment(file)
|
||||
await limiter.add(() => createAttachment(file))
|
||||
}
|
||||
}
|
||||
await limiter.waitProcessing()
|
||||
progress = false
|
||||
}
|
||||
|
||||
@ -257,17 +262,17 @@
|
||||
return
|
||||
}
|
||||
saved = true
|
||||
const promises: Promise<any>[] = []
|
||||
const limiter = new RateLimiter(10)
|
||||
newAttachments.forEach((p) => {
|
||||
const attachment = attachments.get(p)
|
||||
if (attachment !== undefined) {
|
||||
promises.push(saveAttachment(attachment))
|
||||
void limiter.add(() => saveAttachment(attachment))
|
||||
}
|
||||
})
|
||||
removedAttachments.forEach((p) => {
|
||||
promises.push(deleteAttachment(p))
|
||||
void limiter.add(() => deleteAttachment(p))
|
||||
})
|
||||
await Promise.all(promises)
|
||||
await limiter.waitProcessing()
|
||||
newAttachments.clear()
|
||||
removedAttachments.clear()
|
||||
saveDraft()
|
||||
|
Loading…
Reference in New Issue
Block a user