Decrease number of SQL queries when moving an issue between epic swimlanes in GraphQL
When using issueMoveList
GraphQL to move an issue between epic swimlanes and also move an issue between lists (IOW diagonally), then number of SQL queries exceeds 100 limit.
Reproducible by:
- comment out query limit disablement in app/graphql/mutations/boards/issues/issue_move_list.rb
- run
rspec ee/spec/requests/api/graphql/mutations/boards/issues/issue_move_list_spec.rb
In general the problem is that Issue::UpdateService becomes overloaded with additional features which can be updated when updating the issue. Currently the request (in the spec) does 135 queries. There is no simple solution w/o doing some bigger refactoring, but we can consider following approaches to limit the overall count:
- move as much as possible "hook-related-stuff" into an async worker - these might be: todos creation/cleanup, issue metrics (
ensure_metrics
) callback, maybe system notifications? Though this will save enough queries to get under 100 queries limit. - cache some queries - the impact though would be relatively small (given we are hitting the limit in the spec itself)
- consider using more lightweight separate service for moving issues between board lists (instead of Issues::UpdateService) - I'm not sure though if this is a good idea because moving an issue between lists actually updates issue itself (relative position, epic_id, labels/assigness...)
Edited by Jan Provaznik