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

418 views Asked by At

We are developing a storage app that, among other things, syncs and backs up photos on the user's device with the cloud. We use the file size and image name together to form a makeshift hash for comparison. The problem we are facing is when users with a large number of photos on their device (> 10K) first sign up, fetching and retrieving the file size of the photos takes a long time ~ 3.5 minutes.

We use PHImageManager like so:

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

which is called from 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()
        }
    }

The file size is not part of the metadata and so the retrieval takes time (this is not the case in Android for example).

Does anyone know of a way of speeding this up? Maybe a bulk retrieval?

Thank you in advance.

0

There are 0 answers