vector-im/element-ios/issues/4753 - Prevent unnecessary audio file conversions if final file already exists on disk.

This commit is contained in:
Stefan Ceriu
2021-12-02 14:32:32 +02:00
committed by Stefan Ceriu
parent c70c4fb70a
commit f21a469f9a
2 changed files with 9 additions and 3 deletions
@@ -208,9 +208,9 @@ class VoiceMessageAttachmentCacheManager {
return
}
let newURL = temporaryFilesFolderURL.appendingPathComponent(ProcessInfo().globallyUniqueString).appendingPathExtension("m4a")
let newURL = temporaryFilesFolderURL.appendingPathComponent(identifier).appendingPathExtension("m4a")
VoiceMessageAudioConverter.convertToMPEG4AAC(sourceURL: URL(fileURLWithPath: filePath), destinationURL: newURL) { result in
let conversionCompletion: (Result<Void, VoiceMessageAudioConverterError>) -> Void = { result in
self.workQueue.async {
switch result {
case .success:
@@ -245,6 +245,12 @@ class VoiceMessageAttachmentCacheManager {
}
}
}
if FileManager.default.fileExists(atPath: newURL.path) {
conversionCompletion(Result.success(()))
} else {
VoiceMessageAudioConverter.convertToMPEG4AAC(sourceURL: URL(fileURLWithPath: filePath), destinationURL: newURL, completion: conversionCompletion)
}
}
private func sampleFileAtURL(_ url: URL, duration: TimeInterval, numberOfSamples: Int, identifier: String, semaphore: DispatchSemaphore) {