PeterStaev / nativescript-azure-mobile-apps

:cloud: NativeScript plugin for working with Microsoft Azure Mobile Apps services
Apache License 2.0
30 stars 10 forks source link

[Android only] Query Result Handling Problem #31

Closed maekawataiki closed 5 years ago

maekawataiki commented 5 years ago

This only appears on Android.

I am using "nativescript-azure-mobile-apps": "^2.0.3" "tns-android": { "version": "4.2.0" }

When Query Result size is over 50, Azure only returns first 50 results. (at least on my environment now)

As a result, the returned result contains link to next query result.

For example:

{
"nextLink": "https://<yourResourceName>.azurewebsites.net/ ... skip=50",
"results": [ ... ]
}

When Query Result size is less than 50, the result is just an array.

On iOS this doesn't happen. It just returns array of maximum size 50.

Shouldn't it always return array like iOS version?

PeterStaev commented 5 years ago

Can you provide more details what your query is like?

The plugin directly calls the native libs so not sure what might be causing the generation of the nextLink. And since I haven't used the plugin in any of my apps, I don't have any real life cases which I can link to this. But reading through some past GH issues, seems there are decorators which you use on your controller methods: https://github.com/Azure/azure-mobile-apps-net-server/blob/master/e2etest/Controllers/Table/MoviesController.cs#L26 By any chance you applied something to your backend?

maekawataiki commented 5 years ago

My query is like this.

let table = this.client.getTable("Team");
let query = table.where().field("deleted").eq(false).orderBy("name", SortDir.Asc); // get all available records on table
query.read().then(results => {
console.log(results);
}).catch(error => console.log(error))

I've tested the case in more detail.

Let X = maximum size of result set on Azure, then there are 2 cases. Case1: If results.length > X, then the result contains "nextLink". Case2: If results.length <= X, then the result is array.

For example, assuming there are records more than 100 and X = 50. When you specify .top(100), then the result contains "nextLink". When you specify .top(50), then the result is array. When you don't specify, then the result contains "nextLink".

According to this post, it seems X = 50 is the default value on Azure. It can be increased, but it is not preferred solution because of delay and large memory issue.

For now, limiting the result size by .top(X) is a workaround that always returns an array. Not specifying it may return an object instead of array and break the program.

PeterStaev commented 5 years ago

Interesting, so I guess Azure always returns max of 50 items. Strange why it works differently on iOS though...