Is there a way to speed up getting PHAsset data like filesize?

We are developing a data storage application that, among other things, synchronizes and backs up photos on a user device with the cloud. We use the file size and image name together to form a temporary hash for comparison. The problem that we are facing is that users with a large number of photos on their device (> 10K) first register, extracting and extracting the size of photo files takes a lot of time ~ 3.5 minutes.

We use PHImageManager as follows:

photoManager.requestImageData(for: asset, options: options, resultHandler: callback)

which is called and processed here:

let semaphore = DispatchSemaphore(value: 0)
    let operation = GetOriginalImageOperation(photoManager: self.photoManger,
                                              asset: asset) { (data, string, orientation, dict) in
        if let wrapDict = dict, let dataValue  = data {
            if let name = asset.originalFilename {
                originalFileName = name
            }
            if let unwrapedUrl = wrapDict["PHImageFileURLKey"] as? URL {
                url = unwrapedUrl
            }
            size = UInt64(dataValue.count)
            md5 = String(format: "%@%i", originalFileName, size)

            semaphore.signal()
        } else {
            semaphore.signal()
        }
    }

File size is not part of the metadata, so the search takes time (for example, this does not apply to Android).

- , ? , ?

.

+4

Source: https://habr.com/ru/post/1693926/


All Articles