Start a new topic
Answered

Duplicate Entity IDs

I have a UITableView that I am fetching data for. I have a function that gets entityIDs for KCSFiles, and it works fine if there are not duplicate IDs. 


The issue is when the same user posts multiple times, only one KCSFile applies (Since it is the same user with the same profile picture). E.g. two IDs given (that are the same) and one KCSFile output. I need this to return every time, regardless of if it is the same file. 

 

            for ID in IDs {
            print(ID)
                KCSFileStore.downloadFile(ID, options: nil, completionBlock: { (pictures, error) in
                    if let pictures = pictures as? [KCSFile] {
                        for picture in pictures {
                            print(picture)
                        }
                    }
                }, progressBlock: nil)
            }

 Outputs:  

02c5040b-b9fe-49b8-b40c-62cd3559fcd2

02c5040b-b9fe-49b8-b40c-62cd3559fcd2

<KCSFile: 0x7fedb8da49d0>


Best Answer

Hi Elijah,

The error that these functions would throw when downloading the duplicate files is "Download already in progress.". So if you capture all the file id's for which this error occured and then retry downloading only these files again once the initial transfer is done, you should get the respective KCSFile objects filled in (and they would come from the cache).


Thanks,

Pranav

Kinvey Support


Answer

Hi Elijah,

The error that these functions would throw when downloading the duplicate files is "Download already in progress.". So if you capture all the file id's for which this error occured and then retry downloading only these files again once the initial transfer is done, you should get the respective KCSFile objects filled in (and they would come from the cache).


Thanks,

Pranav

Kinvey Support

I just want downloadData/downloadFile to return a picture.localURL or .remoteURL regardless of any conditions. 


Essentially I want to fetch a profile picture from a user relation–but duplicate IDs (of the user or their picture) only results in KCSFileStore fetching one object. 


Here is the custom Post object (simplified):  

class Post: NSObject {
    var entityId: String?
    var user: KCSUser?
    override func hostToKinveyPropertyMapping() -> [NSObject : AnyObject]! {
        return [
            "entityId": KCSEntityKeyId,
            "user": "user",
        ]
    }
    override static func kinveyPropertyToCollectionMapping() -> [NSObject : AnyObject]! {
        return [
            "user": KCSUserCollectionName
        ]
    }
}

Let's assume I fetch all posts and users with a function and pass them in a completion block. All of the posts and users have distinct pointer addresses, and this works fine. However, when I try to fetch the profile pictures from each user, if a user is repeated, only one profile picture is fetched. I have tried KCSFileStore.downloadData and .downloadFile.     


    static func fetchPictures() {
        fetchPostsAndUsers { (Posts, Users) in
            for user in Users {
                let pictureId = user.getValueForAttribute(kKinveyUser.profile_picture)
                KCSFileStore.downloadData(pictureId, completionBlock: { (pictures, error) in
                    if let pictures = pictures {
                        // completion block
                    }
                }, progressBlock: nil)
            }
        }
    }

 

Hi Elijah,

Can you let me know the error that you see in the completion block handler?
When you are fetching the ID's would it be possible to send back only distinct id's?
If you could provide additional information about the scenario as to how you are ending up with duplicate id's (any more code snippets would also do) that will enable to help better.

Thanks,
Pranav

Kinvey Support

Login or Signup to post a comment