fix: filters and limits in GET/jobs to get consistent results #1866
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
GET/jobs and fullQuery/jobs need to apply CASL rules after retrieving the jobs because these rules depend on each job configuration. This was causing inconsistencies in the results of endpoints because the filters and limits of the search where applied first, and the CASL rules afterwards. These rules would exclude jobs that the user does not have access to, causing discrepancies if the results where being paginated.
For example, when applying limits like so:
{ "where": { "type": "archive" }, "limits": { "skip": 0, "limit": 10 } }
one would expect the first page to contain 10 jobs, and similarly the rest of the pages, until we reach the end of the list. However, since the execution order was1. where + limits, 2. CASL rules
, there were cases where a page would contain less than 10 jobs even if the remaining number of jobs was more than that.Motivation
Return consistent number of jobs per page, when pagination is applied.
Changes:
Instead of using
findAll
andfindquery
fromjobs.service
, introducefindByFilters
andapplyFilterLimits
, so that they can be applied separarately and the execution order can change to1. where, 2. CASL rules, 3. limits
. This way the pagination will be done after all filtering has been applied. Now GET/jobs, fullQuery/jobs as well as fullFacet/jobs have been updated to always return consistent results.Tests included
Documentation
official documentation info