Parse-SDK-Android
Parse-SDK-Android copied to clipboard
Parse query from the network is much faster then from the local datastore
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
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
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:
- Your test environment
- Your Parse SDK version
- The code snippet how you store data to local datastore and query from local datastore. Thx
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
- 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...)
- 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);
}
});
}
even without the include - the local query is waaaay slower then the network request
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.
+1 but for iOS
I have same problem
I have the same problem here +1
I have the same problem a while ago, I solved mine by using different pinNames.
I have the same problem
@xdgimf : What do you mean by 'using different pinNames' ?
Could you fix the problem? I have the same problem!
@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)
.
Sam problem, issue is open in 2017, no news about this?