Skip to content

Fix work item children order by relative position

What does this MR do and why?

Related to #408075 (closed)

When querying work items children that are ordered by relative position, the order is incorrect when the children are preloaded (multiple work items query).

This is due to WorkItem#work_item_children_keyset_order using includes(:child_links) instead of includes(:parent_link) (see #408075 (comment 1362118272) for more context).

This MR changes the relationship included and adds order examples to spec/requests/api/graphql/project/work_items_spec.rb.

How to set up and validate locally

  1. Create an Objective with 2 key result children
  2. Visit http://gdk.test:3000/-/graphql-explorer and run the following queries:
Get children ids
query getObjective {
  project(fullPath: "gitlab-org/gitlab-test") {
    workItems(types: OBJECTIVE, first: 1) {
      edges {
        node {
          id
          widgets {
            ... on WorkItemWidgetHierarchy {
              children { edges { node { id } }
              }
            }
          }
        }
      }
    }
  }
}
Move Key Result 2 before Key Result 1
mutation reorderKeyResults {
  workItemUpdate(input: {id: KR_2_ID, hierarchyWidget: {relativePosition: BEFORE, adjacentWorkItemId: KR_1_ID }}) {
    errors
  }
}
  1. When visiting the Objetive or running the first query again, the children order should have changed (key result 2 is first in the list)

Database changes

..."work_item_parent_links"."work_item_parent_id" = "issues"."id"

..."work_item_parent_links"."work_item_id" = "issues"."id"

Previous query
SELECT
	"issues".*
FROM
	"issues"
	LEFT OUTER JOIN "work_item_parent_links" ON "work_item_parent_links"."work_item_parent_id" = "issues"."id"
WHERE
	"issues"."id" IN (ID1, ID2, ID3)
ORDER BY
	"work_item_parent_links"."relative_position" ASC NULLS LAST,
	"issues"."created_at" ASC
New query
SELECT
	"issues".*
FROM
	"issues"
	LEFT OUTER JOIN "work_item_parent_links" ON "work_item_parent_links"."work_item_id" = "issues"."id"
WHERE
	"issues"."id" IN (ID1, ID2, ID3)
ORDER BY
	"work_item_parent_links"."relative_position" ASC NULLS LAST,
	"issues"."created_at" ASC

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