Skip to content

Create notes for new issuable links in async job

Related to #419555 (closed)

What does this MR do and why?

  • What

System notes creation for new work item links are being moved to an async job. Also, notes for the source work item are being combined into a single note.

  • Why

When creating issuable links with IssuableLinks::CreateService the number of executed SQL queries can be pretty high due to validations, permission checks and system notes creation. For work items links specifically, we had to introduce a limit of 3 for the number items that can be linked at the time so we could safely disable the query limiting because tests were failing for executing > 100 queries.

This limit of 3 was a temporary solution (while the feature is still behind a FF) but needs to be increased to 10 in order to be ready for GA. Given that the creation of the system notes has the biggest impact on the number of queries (~50%) this MR moves it to an async job. We took a similar approach for epic-issue links in !64524 (merged) to reduce the number of queries for this type of link.

Note that I'll enable the query limiting and increase the limit for the number of links allowed in a follow-up. I have included this here because it's just a small change.

Screenshots or screen recordings

Click to expand
Before After
before_two_notes after_one_note

How to set up and validate locally

  1. Using rails console enable the feature flag
Feature.enable(:linked_work_items)
  1. Create a work item of type task and take note of its ID
Click to expand
author, project = User.first, Project.first
wi_type = WorkItems::Type.find_by(base_type: 'task')
task = WorkItem.create!(title: "Source Task", project: project, author: author, work_item_type: wi_type)
  1. Create 6 more tasks and take note of their ID
Click to expand
related1 = WorkItem.create!(title: "Related 1", project: project, author: author, work_item_type: wi_type)
related2 = WorkItem.create!(title: "Related 2", project: project, author: author, work_item_type: wi_type)
blocked1 = WorkItem.create!(title: "Blocked 1", project: project, author: author, work_item_type: wi_type)
blocked2 = WorkItem.create!(title: "Blocked 2", project: project, author: author, work_item_type: wi_type)
blocking1 = WorkItem.create!(title: "Blocking 1", project: project, author: author, work_item_type: wi_type)
blocking2 = WorkItem.create!(title: "Blocking 2", project: project, author: author, work_item_type: wi_type)
  1. Make sure that background jobs are running correctly using gdk tail rails-background-jobs

  2. Visit https://gdk.test:3000/-/graphql-explorer and use the following mutation (replace task IDs) to add linked items

mutations
mutation addRelated {
  workItemAddLinkedItems(input: {id: "gid://gitlab/WorkItem/<task_id>", workItemsIds: ["gid://gitlab/WorkItem/<related1_id>", "gid://gitlab/WorkItem/<related2_id>"]}) {
    errors
    message
  }
}

mutation addBlocked {
  workItemAddLinkedItems(input: {id: "gid://gitlab/WorkItem/<task_id>", workItemsIds: ["gid://gitlab/WorkItem/<blocked1_id>", "gid://gitlab/WorkItem/<blocked2_id>"], linkType: BLOCKS}) {
    errors
    message
  }
}

mutation addBlocking {
  workItemAddLinkedItems(input: {id: "gid://gitlab/WorkItem/<task_id>", workItemsIds: ["gid://gitlab/WorkItem/<blocking1_id>", "gid://gitlab/WorkItem/<blocking2_id>"], linkType: BLOCKED_BY}) {
    errors
    message
    workItem {
      webUrl
    }
  }
}
  1. Visit the source task (URL returned in the last mutation) and verify that notes were created correctly. If not present try gdk restart rails-background-jobs.

notes_matching_linked_items

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 Eugenia Grieff

Merge request reports

Loading