Commit 4786e97f authored by Eulyeon Ko's avatar Eulyeon Ko Committed by Eulyeon Ko

Apply reviwer suggestions 2

Extract initialize_relative_positions into Board::Issues::ListService
parent 2a9bdd55
...@@ -27,9 +27,7 @@ module Boards ...@@ -27,9 +27,7 @@ module Boards
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params) list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
issues = issues_from(list_service) issues = issues_from(list_service)
if Gitlab::Database.read_write? && !board.disabled_for?(current_user) ::Boards::Issues::ListService.initialize_relative_positions(board, current_user, issues)
Issue.move_nulls_to_end(issues)
end
render_issues(issues, list_service.metadata) render_issues(issues, list_service.metadata)
end end
......
...@@ -17,17 +17,11 @@ module Resolvers ...@@ -17,17 +17,11 @@ module Resolvers
service = ::Boards::Issues::ListService.new(list.board.resource_parent, context[:current_user], filter_params) service = ::Boards::Issues::ListService.new(list.board.resource_parent, context[:current_user], filter_params)
pagination_connections = Gitlab::Graphql::Pagination::Keyset::Connection.new(service.execute) pagination_connections = Gitlab::Graphql::Pagination::Keyset::Connection.new(service.execute)
initialize_relative_positions(pagination_connections.items, list.board) ::Boards::Issues::ListService.initialize_relative_positions(list.board, current_user, pagination_connections.items)
pagination_connections pagination_connections
end end
def initialize_relative_positions(issues, board)
if Gitlab::Database.read_write? && !board.disabled_for?(current_user)
Issue.move_nulls_to_end(issues)
end
end
# https://gitlab.com/gitlab-org/gitlab/-/issues/235681 # https://gitlab.com/gitlab-org/gitlab/-/issues/235681
def self.complexity_multiplier(args) def self.complexity_multiplier(args)
0.005 0.005
......
...@@ -9,6 +9,14 @@ module Boards ...@@ -9,6 +9,14 @@ module Boards
IssuesFinder.valid_params IssuesFinder.valid_params
end end
# It is a class method because we cannot apply it
# prior to knowing how many items should be fetched for a list.
def self.initialize_relative_positions(board, current_user, issues)
if Gitlab::Database.read_write? && !board.disabled_for?(current_user)
Issue.move_nulls_to_end(issues)
end
end
private private
def order(items) def order(items)
......
...@@ -139,4 +139,51 @@ RSpec.describe Boards::Issues::ListService do ...@@ -139,4 +139,51 @@ RSpec.describe Boards::Issues::ListService do
end end
# rubocop: enable RSpec/MultipleMemoizedHelpers # rubocop: enable RSpec/MultipleMemoizedHelpers
end end
describe '.initialize_relative_positions' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :empty_repo) }
let_it_be(:board) { create(:board, project: project) }
let_it_be(:backlog) { create(:backlog_list, board: board) }
let(:issue) { create(:issue, project: project, relative_position: nil) }
context "when 'Gitlab::Database::read_write?' is true" do
before do
allow(Gitlab::Database).to receive(:read_write?).and_return(true)
end
context 'user cannot move issues' do
it 'does not initialize the relative positions of issues' do
described_class.initialize_relative_positions(board, user, [issue])
expect(issue.relative_position).to eq nil
end
end
context 'user can move issues' do
before do
project.add_developer(user)
end
it 'initializes the relative positions of issues' do
described_class.initialize_relative_positions(board, user, [issue])
expect(issue.relative_position).not_to eq nil
end
end
end
context "when 'Gitlab::Database::read_write?' is false" do
before do
allow(Gitlab::Database).to receive(:read_write?).and_return(false)
end
it 'does not initialize the relative positions of issues' do
described_class.initialize_relative_positions(board, user, [issue])
expect(issue.relative_position).to eq nil
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment