FOUR-31892: Optimize Tasks API index endpoint query performance#8881
Open
AugustoLopezProcess wants to merge 5 commits into
Open
FOUR-31892: Optimize Tasks API index endpoint query performance#8881AugustoLopezProcess wants to merge 5 commits into
AugustoLopezProcess wants to merge 5 commits into
Conversation
|
devmiguelangel
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.




Issue & Reproduction Steps
The Tasks list API (
GET /api/1.0/tasks) is slow on instances with a large number of tasks, especially when the inbox uses thenon_system=truefilter and eager-loads related models (processRequest,process,user,draft, etc.).How to reproduce:
process_request_tokensrecords).nonSystemfilter useswhereHas('process.categories'), which triggers expensive Process global scopes. The base query also loads heavy JSON columns (data,self_service_groups,token_properties) and over-fetches relation columns.Solution
indexOptimized()to the API v1.1TaskController, reusing existing index filtering logic with an optimized query path.indexOptimizedBaseQuery()andapplyIndexFieldSelection()to:includerelations with minimal column selection.fields/columnsare provided.columnsto the minimum DB fields needed.scopeNonSystem()onProcessRequestTokento accept an$optimizedflag; when enabled, uses a directEXISTSsubquery instead ofwhereHas('process.categories'), avoiding Process global scopes.nonSystempath throughexcludeNonVisibleTasks()via anoptimizedrequest flag.GET /api/1.1/tasks/tasksOptimized.OPTIMIZED_TASKS_ENABLEDconfig (config/app.php, defaulttrue); when enabled, the standard v1.0TaskController::index()delegates to the optimized implementation.How to Test
OPTIMIZED_TASKS_ENABLED=truein.env(or omit it to use the default).GET /api/1.0/tasks?non_system=true&include=processRequest,process,user,draft&status=ACTIVEGET /api/1.1/tasks/tasksOptimized(same query params)OPTIMIZED_TASKS_ENABLED=false, clear config cache, repeat the v1.0 callnon_system=truestill excludes system-category processes in both paths.processesIManage=true, overdue filter, pagination, and column/field selection viacolumnsorfieldsparams.Related Tickets & Packages
Code Review Checklist