Use work_item labels when migration finished

What does this MR do and why?

This introduces the MigrationStatus for checking if a migration has been finished or not. Instead of waiting until a background migration has been finalized, we can already change our queries when the background migration has been finished.

Especially for label_links we gain performance as we only need to read the labels of a work item instead of performing a UNION query also for its legacy epic label_link.

This MR changes the BulkResolver and LabelFilter to start reading only from the work_item labels when the migration has been completed. Other changes to read the label_links only from the work item will follow.

References

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Enable work_item_planning_view feature flag
  2. Enable use_namespace_traversal_ids_for_work_items_finder feature flag
  3. Enable the Performance bar
  4. Go to a Group -> Work Items
  5. Filter the work items based on a label
  6. Check the GetWorkItemsFullEE or GetWorkItemsSlimEE` query

Before this MR: You'd see that the query for filtering labels is a UNION query

AND EXISTS (
SELECT "label_links".*
FROM (
    (
      SELECT "label_links"."label_id"
      FROM "label_links"
      WHERE "label_links"."target_type" = 'Issue'
        AND "label_links"."target_id" = "issues"."id"
        AND "label_links"."label_id" = 10690700
    )
    UNION ALL
    (
      SELECT "label_links"."label_id"
      FROM "label_links"
      WHERE "label_links"."target_type" = 'Epic'
        AND "label_links"."target_id" = (
          SELECT "epics"."id"
          FROM "epics"
          WHERE "epics"."issue_id" = "issues"."id"
        )
        AND "label_links"."label_id" = 10690700
    )
  ) label_links
)

With this MR

First ensure that the background job finished (status = 3):

select id, status from batched_background_migrations where job_class_name = 'MigrateEpicLabelLinksToWorkItems';
 id | status
----+--------
 22 |      3

Then you see on the query that it no longer performs the UNION query as it looks like:

 WHERE "label_links"."target_type" = 'Issue' AND "label_links"."target_id" = "issues"."id" AND "label_links"."label_id" = 111)

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Nicolas Dular

Merge request reports

Loading