Parse-SDK-Android icon indicating copy to clipboard operation
Parse-SDK-Android copied to clipboard

Parse query from the network is much faster then from the local datastore

Open paatz04 opened this issue 9 years ago • 14 comments

Hey guys,

I'm having problems using the the parse local database. Every single query no matter if with filters or includes, takes longer from the local database then from the network. But only the first call - so it's probably related to the initialization of the local db.

Anything I can do here? It can be really slow... Network request might take 0.1s and the local data storage takes a few seconds (up to 5). After the local db is initialized, local queries are as fast as they should be.

Thanks Cheers

paatz04 avatar Oct 01 '15 21:10 paatz04

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

Please try the latest SDK. Our release notes have details about what issues were fixed in each release.

In addition, you might find the following resources helpful:

  • Documentation: https://www.parse.com/docs
  • Google Groups: https://groups.google.com/forum/#!forum/parse-developers
  • Stack Overflow: http://stackoverflow.com/tags/parse.com

parse-github-bot avatar Oct 02 '15 17:10 parse-github-bot

Hi @paatz04, I try in my emulator and device, and the local datastore works fine. The first query takes around 50ms - 100ms. And it is really wried for you problem, since if you enable local datastore, in Parse.initialize() when we try to get currentUser, we actually try to read from local datastore and create and open the db if necessary. So when you try to query from the local datastore, the db should have been initialized. In your case, could you provide us with these information:

  1. Your test environment
  2. Your Parse SDK version
  3. The code snippet how you store data to local datastore and query from local datastore. Thx

wangmengyan95 avatar Oct 02 '15 17:10 wangmengyan95

Hey @wangmengyan95,

first thank you for the respond. I figured out what might have caused the super delayed respond. Using include in my local query slowed down the whole local data storage. It seems like the local include is less performant then the network one.

Unfortunately removing include in my big query and just fetch for data each time I need it got me to the next issue. I already reported it here.

It's just around 50 parse object ... wondering why it gets that slow with the include

  1. I'm always testing on different devices (Nexus 4, Nexus 5, different HTC devices, Samsung S5 and the simulator) with various OS versions (4.x.x,5.1.1,6...)
  2. always the newest parse sdk version 1.10.2
protected void loadRequestList() {

    if (requestList.size() == 0) {
        ParseQuery<JobRequest> query = JobRequest.getQuery();
        query.fromLocalDatastore();
        // query.include("jobProgress");
        //query.include("contact");

        if (DataHandler.getInstance().getUser().isHost())
            query.orderByDescending("scheduledStartTime");
        else
            query.orderByDescending("createdAt");

        query.findInBackground(new FindCallback<JobRequest>() {

            @Override
            public void done(List<JobRequest> list, ParseException e) {
                if (e == null) {
                    requestList = list;

                    //Load Sorted Requests
                    loadSortedRequests();

                    setChanged();
                    notifyObservers(false);

                }
                if (CheckNetwork.checkInternet(App.getMainContext())) {
                    loadRequestsBackendList();
                } else {
                    setChanged();
                    notifyObservers(true);
                }

            }
        });
    } else {
        if (CheckNetwork.checkInternet(App.getMainContext())) {
            loadRequestsBackendList();
        } else {
            setChanged();
            notifyObservers(true);
        }
    }


}

private void loadRequestsBackendList() {
    ParseQuery<JobRequest> backendQuery = JobRequest.getQuery();
    backendQuery.include("jobProgress");
    backendQuery.whereGreaterThan("updatedAt", requestsDateSync);
    backendQuery.orderByDescending("scheduledStartTime");
    backendQuery.findInBackground(new FindCallback<JobRequest>() {

        @Override
        public void done(List<JobRequest> list, ParseException e) {
            if (e == null) {

                boolean needsSort = false;
                for (JobRequest updatedJob : list) {
                    int indexOf = requestList.indexOf(updatedJob);
                    if (indexOf != -1) {
                        requestList.set(indexOf, updatedJob);
                    } else {
                        requestList.add(updatedJob);
                        needsSort = true;
                    }

                    if (updatedJob.getUpdatedAt().after(requestsDateSync))
                        requestsDateSync = updatedJob.getUpdatedAt();


                }

                ParseObject.pinAllInBackground(list);

                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putString(REQUESTS_DATE, StringParserOBJ.objectToString(requestsDateSync));
                editor.commit();


                if (needsSort) {
                    Collections.sort(requestList, new Comparator<JobRequest>() {
                        public int compare(JobRequest o1, JobRequest o2) {
                            if (o1.getScheduledStartTime().compareTo(o2.getScheduledStartTime()) > 0)
                                return -1;
                            else
                                return 1;
                        }
                    });

                    //Load Sorted Requests

                }
                if (list.size() > 0)
                    loadSortedRequests();


            }
            setChanged();
            notifyObservers(true);


        }
    });
}

paatz04 avatar Oct 07 '15 21:10 paatz04

even without the include - the local query is waaaay slower then the network request

paatz04 avatar Oct 09 '15 18:10 paatz04

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

parse-github-bot avatar Oct 16 '15 18:10 parse-github-bot

+1 but for iOS

pjchavarria avatar Dec 05 '15 21:12 pjchavarria

I have same problem

btsken avatar Feb 19 '16 09:02 btsken

I have the same problem here +1

jehannn avatar Jun 14 '16 03:06 jehannn

I have the same problem a while ago, I solved mine by using different pinNames.

xdgimf avatar Jun 15 '16 04:06 xdgimf

I have the same problem

sofiablaunshtein avatar Jun 19 '16 06:06 sofiablaunshtein

@xdgimf : What do you mean by 'using different pinNames' ?

swapnilgt avatar Mar 26 '17 07:03 swapnilgt

Could you fix the problem? I have the same problem!

webcreacio avatar May 29 '17 09:05 webcreacio

@webcreacio This is hard to solve currently, and goes down to #279 . If possible, use smaller pins and query.fromPin(String pin).

@swapnilgt it means using object.pinInBackground(String pin) with a pin string. Each pin is a pool of pinned objects. Try to keep pools small and to query the right pin using query.fromPin(pin).

natario1 avatar May 29 '17 10:05 natario1

Sam problem, issue is open in 2017, no news about this?

MattiaConfalonieri avatar May 30 '20 16:05 MattiaConfalonieri