In my database, there is an User table, which has a field called “tasks”. The “tasks” field refers to Tasks table by (one -to-many) relationship.
I need to get First task of a day of an user.
Then my query has filters:
- Users[tasks].objectId = XXX.
- Tasks.createTime >= START_TIME_DAY.
- Tasks.createTime <= END_TIME_DAY.
and order by Tasks.createTime.
the User table has 10 records, and the Tasks table has around 415 records. Both of the tables only has some extra field, and very small data. But the query always takes around 200ms for processing (I calculated the time on my custom service).
I tried to create index on Tasks.createTime but It seems doesn’t work.
Could anyone help me on this.
Thanks,
Nam Nguyen
Hi Nam,
As I understood, you think that the cause of the time delay is in the non-optimize query. But maybe the problem is in ping time to the server.
Regards, Ilya
Hi llya,
Thank for your replying.
But I think the query I have is very simple. I can’t find out any other way for optimizing the query. This is my code:
private static Tasks getFirstTaskOfDay(String userObjectId, Calendar calendar) {
IDataStore<Tasks> tasksTable = Backendless.Data.of(Tasks.class);
QueryOptions options = new QueryOptions();
options.setOffset(0);
options.setPageSize(1);
BackendlessDataQuery query = new BackendlessDataQuery(options);
ArrayList <String> orderBy = new ArrayList <String> ();
orderBy.add("createTime");
options.setSortBy(orderBy);
query.setWhereClause("Users[tasks].objectId = '"
+ userObjectId
+ "' AND (createTime >= "
+ DateUtils.startDayTime(calendar)
+ " AND createTime <="
+ DateUtils.endDayTime(calendar) + ")"
);
long processTime = System.currentTimeMillis(); //calculating process time
BackendlessCollection<Tasks> backendlessCollection = tasksTable.find(query);
List<Tasks> result = backendlessCollection.getCurrentPage();
LOGGER.info("QUERY TIME: " + (System.currentTimeMillis() - processTime)); // => around 200ms
if (result.size() > 0) {
return result.get(0);
}
return null;
}
What do you mean with ping time to server? The processing time is calculating on Backendless server, Not from SDK.
Hi llya,
I think there is no way for me improving the performance.
I just wrote a very simple test:
IDataStore<Tasks> tasksTable = Backendless.Data.of(Tasks.class);
Tasks first = tasksTable .findFirst();
Just get first record, no any filters. The process time is still from 120 -> 170ms.
And as I said before, Every task record has very small amount of data.
There is a lot of things which can impact on performance in online version of Backendless. My suggestion is to use Managed Backendless, where we can improve and tune a lot of server parameters. please contact sales@backendless.com to get more information.