Commit 187a94a5 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '345276-remove-unnecessary-queries-with-vue-issues-list' into 'master'

Avoid queries for issues with vue_issues_list

See merge request gitlab-org/gitlab!79408
parents 2a00d8ea bee36a30
......@@ -209,6 +209,21 @@ class GroupsController < Groups::ApplicationController
end
end
def issues
return super if Feature.disabled?(:vue_issues_list, group, default_enabled: :yaml)
@has_issues = IssuesFinder.new(current_user, group_id: group.id).execute
.non_archived
.exists?
@has_projects = group_projects.exists?
respond_to do |format|
format.html
format.atom { render layout: 'xml.atom' }
end
end
protected
def render_show_html
......
......@@ -10,7 +10,7 @@ class Projects::IssuesController < Projects::ApplicationController
include RecordUserLastActivity
ISSUES_EXCEPT_ACTIONS = %i[index calendar new create bulk_update import_csv export_csv service_desk].freeze
SET_ISSUABLES_INDEX_ONLY_ACTIONS = %i[index calendar service_desk].freeze
SET_ISSUABLES_INDEX_ONLY_ACTIONS = %i[calendar service_desk].freeze
prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }
prepend_before_action(only: [:calendar]) { authenticate_sessionless_user!(:ics) }
......@@ -22,7 +22,10 @@ class Projects::IssuesController < Projects::ApplicationController
before_action :issue, unless: ->(c) { ISSUES_EXCEPT_ACTIONS.include?(c.action_name.to_sym) }
after_action :log_issue_show, unless: ->(c) { ISSUES_EXCEPT_ACTIONS.include?(c.action_name.to_sym) }
before_action :set_issuables_index, if: ->(c) { SET_ISSUABLES_INDEX_ONLY_ACTIONS.include?(c.action_name.to_sym) }
before_action :set_issuables_index, if: ->(c) {
SET_ISSUABLES_INDEX_ONLY_ACTIONS.include?(c.action_name.to_sym) ||
(c.action_name.to_sym == :index && Feature.disabled?(:vue_issues_list, project&.group, default_enabled: :yaml))
}
# Allow write(create) issue
before_action :authorize_create_issue!, only: [:new, :create]
......
......@@ -231,10 +231,10 @@ module IssuesHelper
)
end
def group_issues_list_data(group, current_user, issues, projects)
def group_issues_list_data(group, current_user)
common_issues_list_data(group, current_user).merge(
has_any_issues: issues.to_a.any?.to_s,
has_any_projects: any_projects?(projects).to_s
has_any_issues: @has_issues.to_s,
has_any_projects: @has_projects.to_s
)
end
......
......@@ -6,7 +6,7 @@
= auto_discovery_link_tag(:atom, safe_params.merge(rss_url_options).to_h, title: "#{@group.name} issues")
- if Feature.enabled?(:vue_issues_list, @group, default_enabled: :yaml)
.js-issues-list{ data: group_issues_list_data(@group, current_user, @issues, @projects) }
.js-issues-list{ data: group_issues_list_data(@group, current_user) }
- if @can_bulk_update
= render_if_exists 'shared/issuable/group_bulk_update_sidebar', group: @group, type: :issues
- else
......
......@@ -63,7 +63,7 @@ module EE
end
override :group_issues_list_data
def group_issues_list_data(group, current_user, issues, projects)
def group_issues_list_data(group, current_user)
super.tap do |data|
data[:can_bulk_update] = (can?(current_user, :admin_issue, group) && group.feature_available?(:group_bulk_edit)).to_s
......
......@@ -186,8 +186,6 @@ RSpec.describe EE::IssuesHelper do
describe '#group_issues_list_data' do
let(:current_user) { double.as_null_object }
let(:issues) { [] }
let(:projects) { [] }
before do
allow(helper).to receive(:current_user).and_return(current_user)
......@@ -211,7 +209,7 @@ RSpec.describe EE::IssuesHelper do
group_path: project.group.full_path
}
expect(helper.group_issues_list_data(group, current_user, issues, projects)).to include(expected)
expect(helper.group_issues_list_data(group, current_user)).to include(expected)
end
end
......@@ -230,7 +228,7 @@ RSpec.describe EE::IssuesHelper do
has_multiple_issue_assignees_feature: 'false'
}
result = helper.group_issues_list_data(group, current_user, issues, projects)
result = helper.group_issues_list_data(group, current_user)
expect(result).to include(expected)
expect(result).not_to include(:group_path)
......
......@@ -342,8 +342,6 @@ RSpec.describe IssuesHelper do
describe '#group_issues_list_data' do
let(:group) { create(:group) }
let(:current_user) { double.as_null_object }
let(:issues) { [] }
let(:projects) { [] }
it 'returns expected result' do
allow(helper).to receive(:current_user).and_return(current_user)
......@@ -351,20 +349,23 @@ RSpec.describe IssuesHelper do
allow(helper).to receive(:image_path).and_return('#')
allow(helper).to receive(:url_for).and_return('#')
assign(:has_issues, false)
assign(:has_projects, true)
expected = {
autocomplete_award_emojis_path: autocomplete_award_emojis_path,
calendar_path: '#',
empty_state_svg_path: '#',
full_path: group.full_path,
has_any_issues: issues.to_a.any?.to_s,
has_any_projects: any_projects?(projects).to_s,
has_any_issues: false.to_s,
has_any_projects: true.to_s,
is_signed_in: current_user.present?.to_s,
jira_integration_path: help_page_url('integration/jira/issues', anchor: 'view-jira-issues'),
rss_path: '#',
sign_in_path: new_user_session_path
}
expect(helper.group_issues_list_data(group, current_user, issues, projects)).to include(expected)
expect(helper.group_issues_list_data(group, current_user)).to include(expected)
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