-
Notifications
You must be signed in to change notification settings - Fork 244
Implemented sparse fieldsets support on the backend #1152 #1715
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
base: dev
Are you sure you want to change the base?
Conversation
Eric-Wasson
commented
Oct 27, 2025
Agents overview page with sparse fieldsets applied
Tasks overview page with sparse fieldsets applied. A bit more data gets returned than requested. This is because of the aggregatedData function, which doesn't skip the non-included data yet. There was a todo-comment about that already before my commit (now on line 594 in AbstractBaseAPI.class.php). That's something that I'll improve in the future.
Task overview page with sparse fieldsets applied for 3 different types of data: task, hashlist and hashType
| } | ||
|
|
||
| // If sparse fieldsets (https://jsonapi.org/format/#fetching-sparse-fieldsets) is used, return only the requested data | ||
| if (is_array($sparseFieldsets)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to put the three if statements into a single if statement
src/inc/apiv2/model/tasks.routes.php
Outdated
| if ($keyspaceProgress >= $keyspace && $keyspaceProgress > 0) { | ||
| $status = 3; | ||
|
|
||
| if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("searched", $sparseFieldsets['task']) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first part of the check: " if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets)". is now done twice, I would say do that part as on outer if statement, and then afterwards just check individually for "searched" and "status"
src/inc/apiv2/model/tasks.routes.php
Outdated
| elseif (count($activeAgents) > 0) { | ||
| $status = 1; | ||
|
|
||
| if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("searched", $sparseFieldsets['task']) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "searched" here, should be "status".
|
With this code, will it be possible to simply return the entire object and only specify in the sparse fieldset that you also want some extra agregated data? If not I would suggest to use a different query structure for the aggregated data so that you can add aggregated data with just a few extra additions to your query |
|
Sorry for the late review, but i see that you use indexes in the examples you provide? like for example fields[agents][0] = agentname. what is the 0 used for? I cant see anything about it in the specs. Also When we want to merge this pull request, we should add a frontend pull request that will query for the aggregations where needed, otherwise some part of the ui will break |
Since I used the Firefox devtools I made a slightly wrong implementation of the sparse fieldsets arrays. It's now fixed and can get used properly like this:
What part do you mean would break? As far as I see everything works normally if you don't include the sparse fieldsets and aggregate fieldsets (the default there is to also return everything) in the query (which the frontend currently doesn't do). If you add the sparse fieldsets or aggregate fieldsets in the request then the response will change too. |
|
Ah I see I thought that the aggregation would only happen if it is defined. That would be my preferred solution. But then I think its fine for now to merge it and later make a pull request to make it so that aggregations only happen when its queried for, and then also do a pull request in the frontend where these queries are altered. Can you fix the open merge conflicts? |


