0

Im beginning to scratch the surface of Swift, Parse and IOS, and I had a question regarding how parse performs its findObjectsInBackgroundWithBlock method

In the little snippet below, can someone tell me, if my app will continuously keep downloading 100 objects?

        query.whereKey("location", nearGeoPoint: mygeopoint, withinMiles: 20)
        query.limit = 100
        query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
            if error != nil {
                print(error)
            }else {
                for o in objects! {
                            // do some stuff                        
                }
            }
    }

As a follow up question: lets say I wanted to maintain a reference of objects seen so far, so I don't have to download them again, thereby getting only new objects, how do I do that?

As a follow up to the follow up question: lets say if there are no new objects from the original query and I wanted to execute a new query like

query.whereKey("city", containsString: "San Francisco")

(continue reading) to reflect the logic that, if there are no new objects within 20 miles around me, send me objects that match city = San Francisco : How would i do that?

I have been also reading about PromiseKit - is that something that would be applicable in a scenario like this?

7hacker
  • 1,928
  • 3
  • 19
  • 32
  • OK I think I may have answered my original question, it appears that the objects would be downloaded only once. But my follow-up questions are still a puzzle to me! – 7hacker Dec 03 '15 at 22:54
  • No, you will issue 100 queries against the parse backend, which will get expensive if you have a large number of active users – Paulw11 Dec 03 '15 at 23:06
  • @Paulw11 : so what would be an efficient query to the backend, assuming large number of active users? – 7hacker Dec 03 '15 at 23:12
  • It would be more efficient to update the user's location periodically in the parse back end and then when a new location is added use an `afterSave` cloud code function to determine which users are near that location and send a silent push to those devices. This can trigger the app to query parse to get the updated data – Paulw11 Dec 03 '15 at 23:15
  • @Paulw11 : Thats some new words for me! I'll have to dig into more of that, because what you mention does appear to be a concern. However our user's locations dont need continuous updating. So I am assuming I can still use the 'afterSave cloud code' to issue silent pushes to users when new users come in? But how will I define 'new' or 'seen already' ? And how does this reduce the load on database when the app actually performs a query? – 7hacker Dec 03 '15 at 23:28
  • You know that a location is "new" because in the `afterSave` function you can tell if it is an update or an insert. This doesn't change the load when you perform the query (and the load isn't really the issue, Parse can handle millions of users) but it does reduce *the number* of queries you perform, and that is how parse.com bills you - the number of operations/sec so by using a push you don't have to poll looking for updates. This also reduces your app's network traffic – Paulw11 Dec 03 '15 at 23:36
  • Hi @Paulw11, learnt a lot here, so now its time to go try out everything you suggested before I ask more hypothetical-type questions - but one last question: while also reading about what you mention, I landed on this SO page, [where several users dismiss the scalability of Parse](http://stackoverflow.com/questions/11283729/how-scalable-is-parse). You mention parse can handle millions of users - is the discussion on that thread outdated? – 7hacker Dec 03 '15 at 23:41
  • While I can't personally vouch for their claims as I don't run apps with that many users, that question/answer is 3 years old and dates from a time when they were just out of Beta. The 1000 record response limit for a query still applies, so you need to determine if that may be a factor for you. Personally I have never had an issue with their performance, especially for the price. – Paulw11 Dec 03 '15 at 23:47

0 Answers0