summaryrefslogtreecommitdiff
path: root/app/models/users_statistics.rb
blob: 5b4c0ef37d0ceb669e28420ed90cd111921582e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

class UsersStatistics < ApplicationRecord
  STATISTICS_NAMES = [
    :without_groups_and_projects,
    :with_highest_role_guest,
    :with_highest_role_reporter,
    :with_highest_role_developer,
    :with_highest_role_maintainer,
    :with_highest_role_owner,
    :bots,
    :blocked
  ].freeze

  private

  def highest_role_stats
    return unless Feature.enabled?(:users_statistics)

    {
      owner: batch_count_for_access_level(Gitlab::Access::OWNER),
      maintainer: batch_count_for_access_level(Gitlab::Access::MAINTAINER),
      developer: batch_count_for_access_level(Gitlab::Access::DEVELOPER),
      reporter: batch_count_for_access_level(Gitlab::Access::REPORTER),
      guest: batch_count_for_access_level(Gitlab::Access::GUEST)
    }
  end

  def batch_count_for_access_level(access_level)
    Gitlab::Database::BatchCount.batch_count(UserHighestRole.with_highest_access_level(access_level))
  end
end