From 9538468f113eadab38379818a0b9d567123a3b0b Mon Sep 17 00:00:00 2001 From: Jordan Chapelle Date: Thu, 9 Jan 2025 13:46:22 +0100 Subject: [PATCH] fix: Use concurrentMap instead of for loop --- MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift b/MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift index 1569d3401..4d7b4d04c 100644 --- a/MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift +++ b/MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift @@ -20,6 +20,7 @@ import Alamofire import Foundation import InfomaniakCore import InfomaniakLogin +import InfomaniakConcurrency /// implementing `MailApiCommonFetchable` public extension MailApiFetcher { @@ -86,10 +87,9 @@ public extension MailApiFetcher { } func download(messages: [Message]) async throws -> [URL] { - var downloadedMessageURLs: [URL] = [] let temporaryDirectory = FileManager.default.temporaryDirectory - for message in messages { + return try await messages.concurrentMap { message in let directoryURL = temporaryDirectory.appendingPathComponent(message.uid, isDirectory: true) let destination: DownloadRequest.Destination = { _, response in ( @@ -98,11 +98,10 @@ public extension MailApiFetcher { ) } - let download = authenticatedSession.download(Endpoint.resource(message.downloadResource).url, to: destination) + let download = self.authenticatedSession.download(Endpoint.resource(message.downloadResource).url, to: destination) let messageUrl = try await download.serializingDownloadedFileURL().value - downloadedMessageURLs.append(messageUrl) + return messageUrl } - return downloadedMessageURLs } func quotas(mailbox: Mailbox) async throws -> Quotas {