Query performance with Parse using the local store in Android

My question is very simple, what is the best approach to working with Parse using local storage at the time when I want to request stored objects.

Is it better to run multiple requests in local storage directly in the main thread and avoid embedding a large number of anonymous classes or using a background thread?

It is important to note that this method will be called very often, and the pattern will be repeated in several places with different requests. I evaluate the effectiveness and quality of the code in readability. These methods will be called synchronously, so we can assume that the data will be consistent at any time.

Since objects are stored locally, I expect requests to be very fast in response. Here is an example of how the code will look in both cases.

Option one:

public void processBatches() { 
    ParseQuery<Batch> batchQuery = Batch.getQuery();
    int batchCount = batchQuery.fromLocalDatastore().count();
    List<Batch> batches = batchQuery.fromLocalDatastore().find();
    for(Batch b : batches) {
       // do whatever I need to do
    }
}

Option Two:

public void processBatches() { 
    ParseQuery<Batch> batchQuery = Batch.getQuery();
    int batchCount = batchQuery.fromLocalDatastore().countInBackground(new CountCallback() {
        @Override
        public void done(int i, ParseException e) {
            if (i > 0) {
                batchQuery.findInBackground(new FindCallback<Batch>() {
                    @Override
                    public void done(List<Batch> list, ParseException e) {
                        for (Batch batch : list) {
                            // do whatever I need to do
                        }
                    }
                });
            }
        }
    });
}
+4
source share
2 answers

Well, since in the first option you block the user interface flow, there may be a delay in the user's ability to interact with your application. This is not a good option, because even if it is for a moment, users do not want to wait until they know what is happening. But, if you know that at any time there will be no delay, go ahead and do it.

, , . , . , , ( ), , ? , . , .

AsyncThread find() count() , . , Parse :

public Task<List<T>> findInBackground()
Retrieves a list of ParseObjects that satisfy this query from the source in a background thread.
This is preferable to using ParseQuery.find(), unless your code is already running in a background thread.

Returns:
A Task that will be resolved when the find has completed.

, API .

+3

.

? , , ,

, (, , ), , ,

"// ?" ?

+1

All Articles