Commit aae008ca authored by Michael Kozono's avatar Michael Kozono

Merge branch 'sh-hide-license-breakdown' into 'master'

Hide license breakdown in /admin if user count is high

See merge request gitlab-org/gitlab!18825
parents 31cdfc78 b5570288
......@@ -2,6 +2,7 @@
class Admin::DashboardController < Admin::ApplicationController
include CountHelper
helper_method :show_license_breakdown?
COUNTED_ITEMS = [Project, User, Group].freeze
......@@ -13,6 +14,10 @@ class Admin::DashboardController < Admin::ApplicationController
@groups = Group.order_id_desc.with_route.limit(10)
end
# rubocop: enable CodeReuse/ActiveRecord
def show_license_breakdown?
false
end
end
Admin::DashboardController.prepend_if_ee('EE::Admin::DashboardController')
- breadcrumb_title "Dashboard"
= render_if_exists 'admin/licenses/breakdown', license: @license
- if show_license_breakdown?
= render_if_exists 'admin/licenses/breakdown', license: @license
.admin-dashboard.prepend-top-default
.row
......
---
title: Hide license breakdown in /admin if user count is high
merge_request: 18825
author:
type: performance
......@@ -7,6 +7,8 @@ module EE
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
LICENSE_BREAKDOWN_USER_LIMIT = 100_000
override :index
def index
super
......@@ -18,6 +20,16 @@ module EE
@admin_count = ::User.admins.count
@roles_count = ::ProjectAuthorization.roles_stats
end
# The license section may time out if the number of users is
# high. To avoid 500 errors, just hide this section. This is a
# workaround for https://gitlab.com/gitlab-org/gitlab/issues/32287.
override :show_license_breakdown?
def show_license_breakdown?
return false unless @counts.is_a?(Hash)
@counts.fetch(::User, 0) < LICENSE_BREAKDOWN_USER_LIMIT
end
end
end
end
......@@ -4,6 +4,8 @@ require 'spec_helper'
describe Admin::DashboardController do
describe '#index' do
render_views
it "allows an admin user to access the page" do
sign_in(create(:user, :admin))
......@@ -27,5 +29,31 @@ describe Admin::DashboardController do
expect(response).to have_gitlab_http_status(404)
end
it 'shows the license breakdown' do
sign_in(create(:user, :admin))
get :index
expect(response.body).to include('Users in License')
end
context 'when the user count is high' do
let(:counts) do
described_class::COUNTED_ITEMS.each_with_object({}) { |model, hash| hash[model] = described_class::LICENSE_BREAKDOWN_USER_LIMIT + 1 }
end
before do
expect(Gitlab::Database::Count).to receive(:approximate_counts).and_return(counts)
sign_in(create(:admin))
end
it 'hides the license breakdown' do
get :index
expect(response.body).not_to include('Users in License')
end
end
end
end
......@@ -17,6 +17,7 @@ describe 'admin/dashboard/index.html.haml' do
allow(view).to receive(:admin?).and_return(true)
allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings)
allow(view).to receive(:show_license_breakdown?).and_return(false)
end
it "shows version of GitLab Workhorse" do
......
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