mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-19 14:55:31 +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">
|
<script lang="ts">
|
||||||
import { Attachment } from '@hcengineering/attachment'
|
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 { Asset, IntlString, setPlatformStatus, unknownError } from '@hcengineering/platform'
|
||||||
import {
|
import {
|
||||||
DraftController,
|
DraftController,
|
||||||
@ -183,12 +183,14 @@
|
|||||||
await tick()
|
await tick()
|
||||||
const list = inputFile.files
|
const list = inputFile.files
|
||||||
if (list === null || list.length === 0) return
|
if (list === null || list.length === 0) return
|
||||||
|
const limiter = new RateLimiter(10)
|
||||||
for (let index = 0; index < list.length; index++) {
|
for (let index = 0; index < list.length; index++) {
|
||||||
const file = list.item(index)
|
const file = list.item(index)
|
||||||
if (file !== null) {
|
if (file !== null) {
|
||||||
await createAttachment(file)
|
await limiter.add(() => createAttachment(file))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await limiter.waitProcessing()
|
||||||
inputFile.value = ''
|
inputFile.value = ''
|
||||||
progress = false
|
progress = false
|
||||||
}
|
}
|
||||||
@ -196,13 +198,16 @@
|
|||||||
async function fileDrop (e: DragEvent): Promise<void> {
|
async function fileDrop (e: DragEvent): Promise<void> {
|
||||||
progress = true
|
progress = true
|
||||||
const list = e.dataTransfer?.files
|
const list = e.dataTransfer?.files
|
||||||
|
const limiter = new RateLimiter(10)
|
||||||
|
|
||||||
if (list === undefined || list.length === 0) return
|
if (list === undefined || list.length === 0) return
|
||||||
for (let index = 0; index < list.length; index++) {
|
for (let index = 0; index < list.length; index++) {
|
||||||
const file = list.item(index)
|
const file = list.item(index)
|
||||||
if (file !== null) {
|
if (file !== null) {
|
||||||
await createAttachment(file)
|
await limiter.add(() => createAttachment(file))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await limiter.waitProcessing()
|
||||||
progress = false
|
progress = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,17 +262,17 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
saved = true
|
saved = true
|
||||||
const promises: Promise<any>[] = []
|
const limiter = new RateLimiter(10)
|
||||||
newAttachments.forEach((p) => {
|
newAttachments.forEach((p) => {
|
||||||
const attachment = attachments.get(p)
|
const attachment = attachments.get(p)
|
||||||
if (attachment !== undefined) {
|
if (attachment !== undefined) {
|
||||||
promises.push(saveAttachment(attachment))
|
void limiter.add(() => saveAttachment(attachment))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
removedAttachments.forEach((p) => {
|
removedAttachments.forEach((p) => {
|
||||||
promises.push(deleteAttachment(p))
|
void limiter.add(() => deleteAttachment(p))
|
||||||
})
|
})
|
||||||
await Promise.all(promises)
|
await limiter.waitProcessing()
|
||||||
newAttachments.clear()
|
newAttachments.clear()
|
||||||
removedAttachments.clear()
|
removedAttachments.clear()
|
||||||
saveDraft()
|
saveDraft()
|
||||||
|
Loading…
Reference in New Issue
Block a user