perf: deduplicate order product image requests
This commit is contained in:
@@ -853,14 +853,22 @@ function releaseCargoImagePreviews() {
|
||||
async function loadCargoImagePreviews(resource: UnifiedOrderDetailResource, serial: number) {
|
||||
const tenantId = String(resource.summary.tenantId || '')
|
||||
if (!tenantId) return
|
||||
await Promise.all((resource.order?.cargoes ?? []).map(async (cargo) => {
|
||||
const fileId = cargo.productImageFileId
|
||||
if (fileId === null || fileId === undefined || fileId === '') return
|
||||
const cargoesByFileId = new Map<string, typeof resource.order.cargoes>()
|
||||
for (const cargo of resource.order?.cargoes ?? []) {
|
||||
const fileId = cargo.productImageFileId === null || cargo.productImageFileId === undefined
|
||||
? ''
|
||||
: String(cargo.productImageFileId)
|
||||
if (!fileId) continue
|
||||
const cargoes = cargoesByFileId.get(fileId) ?? []
|
||||
cargoes.push(cargo)
|
||||
cargoesByFileId.set(fileId, cargoes)
|
||||
}
|
||||
await Promise.all([...cargoesByFileId.entries()].map(async ([fileId, cargoes]) => {
|
||||
try {
|
||||
const blob = await downloadPlatformProductImage(tenantId, String(fileId))
|
||||
const blob = await downloadPlatformProductImage(tenantId, fileId)
|
||||
if (serial !== detailRequestSerial || detailRouteKey.value !== `${tenantId}:${orderId.value}`) return
|
||||
const url = URL.createObjectURL(blob)
|
||||
cargo.imageUrl = url
|
||||
cargoes.forEach((cargo) => { cargo.imageUrl = url })
|
||||
cargoImagePreviewUrls.add(url)
|
||||
} catch {
|
||||
// Historical files may have been removed; keep the remaining cargo fields visible.
|
||||
|
||||
Reference in New Issue
Block a user