-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request not being chained for larger limit
values
#86
Comments
Is it the same if you exclude the |
I've been testing this against one of our test servers, test.farmos.dev (login required), using both Node and the browser. I used the const parsed = parseFilter({
land_type: ["field", "bed"],
});
console.log(parsed); That yielded the following url query parameters:
Cleaned up a bit for easier reading
Curiously enough, that test server has 25 beds and 8 fields (again, login required; but @mstenta you should be able to see these). The JSON payload I get back, however, only has the 25 beds. So perhaps it's something wrong with the way the filter parameters are structured for Drupal's JSON:API module? There is also no {
"links": {
"self": {
"href": "https://test.farmos.dev/api/asset/land?filter%5Bgroup-1%5D%5Bgroup%5D%5Bconjunction%5D=OR&filter%5Bland_type-0-filter%5D%5Bcondition%5D%5Bpath%5D=land_type&filter%5Bland_type-0-filter%5D%5Bcondition%5D%5Boperator%5D=%3D&filter%5Bland_type-0-filter%5D%5Bcondition%5D%5Bvalue%5D=bed&filter%5Bland_type-0-filter%5D%5Bcondition%5D%5BmemberOf%5D=group-1"
}
}
} Which would imply to me that there are no other records for that query. Compare a simpler request for all {
"links": {
"next": {
"href": "https://test.farmos.dev/api/asset/plant?page%5Boffset%5D=50&page%5Blimit%5D=50"
},
"self": {
"href": "https://test.farmos.dev/api/asset/plant"
}
}
} I tested that same const farm = farmOS({ remote });
farm.remote.authorize(username, password)
.then(() => farm.schema.fetch())
.then(() => {
const filter = { type: 'asset--plant' };
return farm.asset.fetch({ filter });
})
.then((response) => {
console.log('PLANTS:\n', response.data.length);
}); Which yielded: PLANTS:
55 So that's all to say I'm not exactly sure where the issue lies yet. We should first confirm that there are indeed more than 25 land assets with a I likely won't have the bandwidth to investigate this again until next week at the soonest, but hopefully with that added info, and with anything else @braughtg can learn from their end, @mstenta and others might be able to put the other pieces together. I created a gist with all my test code that others can try out, modify and adapt by cloning: git clone https://gist.github.com/8fa99079e7597fffef88af41c9ebe01e.git limit-farmos-js
cd limit-farmos-js
npm i Then create a TEST_HOST="https://<your-farmos-url>"
TEST_CLIENT_ID="fieldkit"
TEST_USERNAME="<your-username>"
TEST_PASSWORD="<your-password>" Then run: npm test |
No. If I exclude the the Interestingly, if I do So seems suspiciously as if the result is driven by the second (last?) value in the the To further confirm:
|
Weirdly enough the following, which I think is supposed to be equivalent, returns no records. const land = await farm.asset.fetch({
filter: {
type: ["asset--land"],
land_type: {
$or:
[
{$eq: "bed" },
{$eq: "field"},
],
}
},
limit: Infinity, As does the abbreviated version without the |
Ah, OK, yea that makes me think again that there is something awry with the query params themselves, could be worth testing those in browser or REST API testing utility. Meanwhile, @mstenta, care to audit those params I pasted above against the Drupal JSON:API filter spec? Responding from mobile so that's all I can recommend for now. |
I think this is a minor issue with the query params. The
We should double check that this scenario is covered in farmOS.py as well. I forget if I didn't just use a random unique ID.. also might be good to shorten it as much as possible. Maybe find a strategy we should standardize on for this? |
Oh good catch! I'll try fix those params based on that and see if that does it. 🤞 If so, it hopefully will be a simple enough fix to the parsing logic. |
Bingo, right on the money, @paul121. 🙌 I just quickly tested this out on the test server again, and got the expected 33 results, including
And if I had to guess, this is probably the culprit: farmOS.js/src/client/parse-filter.js Line 76 in 63c0479
Changing that to, (params, f, i) => mergeParams(params, parser(f, label, logicDepth + i)) or even just, (params, f, i) => mergeParams(params, parser(f, label, i)) could be all it takes, but I won't have a chance to test it out on my local machine until next week. There's also a chance that the farmOS.js/src/client/parse-filter.js Line 83 in 63c0479
and here: farmOS.js/src/client/parse-filter.js Line 103 in 63c0479
since the parameter is missing there, but I'm less confident about that; the "depth" or farmOS.js/src/client/parse-filter.js Line 67 in 63c0479
but it probably wouldn't hurt anything to increment it there, too.
That is very strange, @braughtg, and I can't be sure, but I suspect it might also be caused by non-unique filter labels (eg, |
This all sounds great! Thanks for the quick diagnosis. I have also in the meantime implemented out a suitable workaround using 2 API calls instead of the one. So that will keep me moving. Thanks! |
We ran into another situation affected by this bug, but this one didn't have a decent work around. It really requires the filtering to happen on the servers side. So I took a whack at a PR to fix this as per the ideas above (which were spot on!) and also updated the tests. |
Describe the bug
The documentation (here: https://github.com/farmOS/farmOS.js/blob/main/docs/entities.md#limiting-fetch-requests) suggests that when the
limit
is set to a value larger than the internal drupal page size that 'fetchwill "chain together successive requests until a given
limit` option is reached." This does not appear to be happening.To Reproduce
Here is a snippet of sample code that I am using that demonstrates the issue:
farm
is afarm
instance created as shown in the demo code in the "Quick start" guide.The database in used has 70 assets that meet the filter criteria, however, the returned
land.data
array has only 25 assets in it. Iflimit
is set to 30, the result still contains only 25 assets. If thelimit
is set to 10, then the result correctly contains only 10 assets.Expected behavior
When
limit
is provided tofetch
it is expected that the result will contain up to a total oflimit
records matching the filter criteria. Whenlimit
is set toInfinity
the result should contain all records matching the filter.Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: