Skip to content

Remove priority sort from board list issues

Heinrich Lee Yu requested to merge optimize-issue-board-lists into master

What does this MR do and why?

Sorts issues on an issue board list by relative position and ID only instead of relative position, label priority, and ID.

Priority sort was added in gitlab-foss!9939 (merged) in the early days of issue boards and I believe we weren't setting positions for all the issues yet. Right now, when an issue is created, the IssuePlacementWorker sets the position to be after the max position.

Also, when a board list is requested, we synchronously set all nil positions so that we don't return issues with null positions.

So priority sort is not needed because it would be very rare where we have collisions on relative_position. Only on invalid data on the database. And the secondary sort on ID should take care of that.

This also fixes a minor bug on the secondary sort so that we sort by id ASC and not id DESC. We move issues to the end as they are created so higher IDs should be at the end. This is similar to what the IssuePlacementWorker does.

Migration output
== 20210927153807 UpdateIssuesRelativePositionIndexes: migrating ==============
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:issues, [:project_id, :relative_position, :id, :state_id], {:name=>"idx_issues_on_project_id_and_rel_position_and_id_and_state_id", :algorithm=>:concurrently})
   -> 0.0142s
-- add_index(:issues, [:project_id, :relative_position, :id, :state_id], {:name=>"idx_issues_on_project_id_and_rel_position_and_id_and_state_id", :algorithm=>:concurrently})
   -> 0.0295s
-- transaction_open?()
   -> 0.0000s
-- indexes(:issues)
   -> 0.0124s
-- remove_index(:issues, {:algorithm=>:concurrently, :name=>"idx_issues_on_project_id_and_rel_asc_and_id"})
   -> 0.0070s
-- transaction_open?()
   -> 0.0000s
-- indexes(:issues)
   -> 0.0118s
-- remove_index(:issues, {:algorithm=>:concurrently, :name=>"idx_issues_on_project_id_and_rel_position_and_state_id_and_id"})
   -> 0.0064s
== 20210927153807 UpdateIssuesRelativePositionIndexes: migrated (0.0884s) =====

== 20210927153807 UpdateIssuesRelativePositionIndexes: reverting ==============
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:issues, [:project_id, :relative_position, :state_id, :id], {:order=>{:id=>:desc}, :name=>"idx_issues_on_project_id_and_rel_position_and_state_id_and_id", :algorithm=>:concurrently})
   -> 0.0123s
-- add_index(:issues, [:project_id, :relative_position, :state_id, :id], {:order=>{:id=>:desc}, :name=>"idx_issues_on_project_id_and_rel_position_and_state_id_and_id", :algorithm=>:concurrently})
   -> 0.0092s
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:issues, [:project_id, :relative_position, :id], {:name=>"idx_issues_on_project_id_and_rel_asc_and_id", :algorithm=>:concurrently})
   -> 0.0117s
-- add_index(:issues, [:project_id, :relative_position, :id], {:name=>"idx_issues_on_project_id_and_rel_asc_and_id", :algorithm=>:concurrently})
   -> 0.0079s
-- transaction_open?()
   -> 0.0000s
-- indexes(:issues)
   -> 0.0123s
-- remove_index(:issues, {:algorithm=>:concurrently, :name=>"idx_issues_on_project_id_and_rel_position_and_id_and_state_id"})
   -> 0.0043s
== 20210927153807 UpdateIssuesRelativePositionIndexes: reverted (0.0648s) =====

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Heinrich Lee Yu

Merge request reports