2020-03-10 20:09:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UsersStatistics < ApplicationRecord
|
2020-04-08 05:09:43 -04:00
|
|
|
scope :order_created_at_desc, -> { order(created_at: :desc) }
|
|
|
|
|
|
|
|
def active
|
|
|
|
[
|
|
|
|
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
|
|
|
|
].sum
|
|
|
|
end
|
|
|
|
|
|
|
|
def total
|
|
|
|
active + blocked
|
|
|
|
end
|
2020-03-18 20:09:27 -04:00
|
|
|
|
2020-04-07 20:09:30 -04:00
|
|
|
class << self
|
2021-11-11 10:10:57 -05:00
|
|
|
def latest
|
|
|
|
order_created_at_desc.first
|
|
|
|
end
|
2020-04-07 20:09:30 -04:00
|
|
|
|
2021-11-11 10:10:57 -05:00
|
|
|
def create_current_stats!
|
|
|
|
create!(highest_role_stats)
|
2020-04-07 20:09:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def highest_role_stats
|
|
|
|
{
|
2021-11-11 10:10:57 -05:00
|
|
|
without_groups_and_projects: without_groups_and_projects_stats,
|
|
|
|
with_highest_role_guest: batch_count_for_access_level(Gitlab::Access::GUEST),
|
|
|
|
with_highest_role_reporter: batch_count_for_access_level(Gitlab::Access::REPORTER),
|
|
|
|
with_highest_role_developer: batch_count_for_access_level(Gitlab::Access::DEVELOPER),
|
|
|
|
with_highest_role_maintainer: batch_count_for_access_level(Gitlab::Access::MAINTAINER),
|
|
|
|
with_highest_role_owner: batch_count_for_access_level(Gitlab::Access::OWNER),
|
|
|
|
bots: bot_stats,
|
|
|
|
blocked: blocked_stats
|
2020-04-07 20:09:30 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_groups_and_projects_stats
|
|
|
|
batch_count_for_access_level(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def bot_stats
|
|
|
|
Gitlab::Database::BatchCount.batch_count(User.bots)
|
|
|
|
end
|
|
|
|
|
|
|
|
def blocked_stats
|
|
|
|
Gitlab::Database::BatchCount.batch_count(User.blocked)
|
|
|
|
end
|
2020-03-18 20:09:27 -04:00
|
|
|
|
2020-04-07 20:09:30 -04:00
|
|
|
def batch_count_for_access_level(access_level)
|
|
|
|
Gitlab::Database::BatchCount.batch_count(UserHighestRole.with_highest_access_level(access_level))
|
|
|
|
end
|
2020-03-18 20:09:27 -04:00
|
|
|
end
|
2020-03-10 20:09:09 -04:00
|
|
|
end
|
2021-03-15 11:09:07 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
UsersStatistics.prepend_mod_with('UsersStatistics')
|