Skip to content

Commit

Permalink
fix: Use concurrentMap instead of for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lebojo committed Jan 9, 2025
1 parent 3af9b99 commit d82fcf2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import Alamofire
import Foundation
import InfomaniakConcurrency
import InfomaniakCore
import InfomaniakLogin

Expand Down Expand Up @@ -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
(
Expand All @@ -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 {
Expand Down

0 comments on commit d82fcf2

Please sign in to comment.