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 683504b commit 9538468
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 @@ -20,6 +20,7 @@ import Alamofire
import Foundation
import InfomaniakCore

Check warning on line 21 in MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Sort import statements alphabetically. (sortImports)
import InfomaniakLogin

Check warning on line 22 in MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Sort import statements alphabetically. (sortImports)
import InfomaniakConcurrency

Check warning on line 23 in MailCore/API/MailApiFetcher/MailApiFetcher+Common.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Sort import statements alphabetically. (sortImports)

/// implementing `MailApiCommonFetchable`
public extension MailApiFetcher {
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 9538468

Please sign in to comment.