Start a new topic

slowness with KCSQuery()

i am using KCSQuery to download comments and usernames from the collection from the backend as below code the issue that is that when i use 


let query = KCSQuery(onField: "Rest_Name", withExactMatchForValue: "Name")


its toke long time to download more then 10 sec 

 





    func NumberOfCells()  {

 

 

 let collection = KCSCollection(fromString: "Comments", ofClass: NSMutableDictionary.self)

 

 

            DownCells.storeComments = KCSCachedStore(collection: collection , options: [ KCSStoreKeyCachePolicy : KCSCachePolicy.LocalOnly.rawValue ])

 

    let query = KCSQuery(onField: "Rest_Name" , withExactMatchForValue: DV.NameOfRest)

 

            DownCells.storeComments.queryWithQuery(query,withCompletionBlock: { (objectsOrNil: [AnyObject]!, errorOrNil: NSError!) -> Void in

                    if errorOrNil == nil {

 

 

                        //extract just the Value field from the entities


                        for d in objectsOrNil as! [NSMutableDictionary] {

 


 

self.userName_.append((d.valueForKey("User_Name") as? String)!) // fill the array of Users Name


                                self.CommentsValue_.append((d.valueForKey("Comments") as? String!)!) // fill the array of Comments

 

                                self.tableView.reloadData()


                                // insert the names of the user comments to doownload ther images

                                // download the image for the user

 


 

self.DownloadImages((d.valueForKey("User_Name") as? String)! + ".jpg") // fill the array of Images Name

 

 

 

                                self.Loading.stopAnimating()

                                self.Loading.hidesWhenStopped = true

 

                        }


                    }

 

 

                self.tableView.reloadData()


 


        },withProgressBlock: nil )

 

 

}


its working fine and download all what i need but toke long time and this will effect the app , is there any way to support me to make it faster or any deferent way to download if my way is wrong 


Rami,


I have few questions for you:


  1. How many records are present in that collection? How many columns are present?
  2. Are you using any hooks for that collection?
  3. What is Kid and name of your app? Also what SDK version you are using?
  4. Do you consistently see the same timing for it or was it better earlier and then deteriorated?
  5. If you change the caching policy does it make any difference?


Thanks,

Pranav

Kinvey Support

Pranav, 


thanks for your reply .


1 - kindly check the attached Screenshot 

2 - no i am not using any hooks 

3 - i did not understand ? the SDK V = KinveyKit-1.40.8

4 - i am using the query in other page of the App but without the "withExactMatchForValue: DV.NameOfRest)" and working fine and fast and its calling more then 80 record with image .


5 - i have change it many time but its no deferents , and please which one of "caching policy" is better ?


Thanks ,

Rami,


  1. Can you log the timings in the comments.OnPreFetch() hook as well as the comments.OnPostFetch() hook ? That way we will know how much time is actually spent in fetching the entities and the remaining time would be due to the network.
  2. Also once you do the above analysis, can you also try using the  KCSCachePolicy.NetworkFirst.rawValue?

 
Let me know the results for the above 2 points.


Thanks,

Pranav

Kinvey Support

Pranav, 


thanks for your reply .


first i don't know how to make the log time in the hook if possible please give me the correct way to do it .

second i have try the  "KCSCachePolicy.NetworkFirst.rawValue?" and it seems its a slower then the "KCSCachePolicy.LocalFirst.rawValue"


Thanks, 

Rami, 

Rami,


Please take a look at the Business Logic reference, the logger and moment modules:
http://devcenter.kinvey.com/html5/reference/business-logic/reference.html
http://devcenter.kinvey.com/html5/reference/business-logic/reference.html#logger-module
http://devcenter.kinvey.com/html5/reference/business-logic/reference.html#moment-module


Here's a small snippet to get you started:
var logger = modules.logger;
var theMoment = modules.moment();
logger.info("Start Time" +theMoment );



Thanks,

Pranav

Kinvey Support

Login or Signup to post a comment