What does this MR do?
EE port of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/30635/commits
Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/48717
EE port of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/30635/commits
Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/48717