I use this code
DatabaseReference dtr = FirebaseDatabase.DefaultInstance.GetReference(path);
dtr.KeepSynced(true);
dtr.OrderByKey().EndAt(lastKey).LimitToLast(5).GetValueAsync()......
Because that path has many childs, I only retrieve 5 results each time with LimitToLast (and also EndAt
later)
The problem is that it takes 4 seconds to retrieve a result, it used to be like 1 second. I'm worried that it's only getting worse. And even though I limit the task to only 5 it still apparently go through all the childs in the DB, my database is already sorted by key by default, what could I do to make it faster?
I tried Frank's solution and changed it to
DatabaseReference dtr = FirebaseDatabase.DefaultInstance.GetReference(path);
var query = dtr.OrderByKey().EndAt(lastKey).LimitToLast(5);
query.KeepSynced(true);
query.GetValueAsync().ContinueWith....
But I still have to wait 4 seconds until task is returned