diff options
Diffstat (limited to 'app/services/users')
-rw-r--r-- | app/services/users/approve_service.rb | 2 | ||||
-rw-r--r-- | app/services/users/assigned_issues_count_service.rb | 63 | ||||
-rw-r--r-- | app/services/users/banned_user_base_service.rb | 2 | ||||
-rw-r--r-- | app/services/users/build_service.rb | 2 | ||||
-rw-r--r-- | app/services/users/keys_count_service.rb | 2 | ||||
-rw-r--r-- | app/services/users/migrate_records_to_ghost_user_service.rb | 5 | ||||
-rw-r--r-- | app/services/users/reject_service.rb | 2 | ||||
-rw-r--r-- | app/services/users/update_highest_member_role_service.rb | 4 |
8 files changed, 74 insertions, 8 deletions
diff --git a/app/services/users/approve_service.rb b/app/services/users/approve_service.rb index 15486ddcd43..353456c545d 100644 --- a/app/services/users/approve_service.rb +++ b/app/services/users/approve_service.rb @@ -42,7 +42,7 @@ module Users end def log_event(user) - Gitlab::AppLogger.info(message: "User instance access request approved", user: "#{user.username}", email: "#{user.email}", approved_by: "#{current_user.username}", ip_address: "#{current_user.current_sign_in_ip}") + Gitlab::AppLogger.info(message: "User instance access request approved", user: user.username.to_s, email: user.email.to_s, approved_by: current_user.username.to_s, ip_address: current_user.current_sign_in_ip.to_s) end end end diff --git a/app/services/users/assigned_issues_count_service.rb b/app/services/users/assigned_issues_count_service.rb new file mode 100644 index 00000000000..6590902587d --- /dev/null +++ b/app/services/users/assigned_issues_count_service.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +module Users + class AssignedIssuesCountService < ::BaseCountService + def initialize(current_user:, max_limit: User::MAX_LIMIT_FOR_ASSIGNEED_ISSUES_COUNT) + @current_user = current_user + @max_limit = max_limit + end + + def cache_key + ['users', @current_user.id, 'max_assigned_open_issues_count'] + end + + def cache_options + { force: false, expires_in: User::COUNT_CACHE_VALIDITY_PERIOD } + end + + # rubocop: disable CodeReuse/ActiveRecord + def uncached_count + # When a user has many assigned issues, counting them all can be very slow. + # As a workaround, we will short-circuit the counting query once the count reaches some threshold. + # + # Concretely, given a threshold, say 100 (= max_limit), + # iterate through the first 100 issues, sorted by ID desc, assigned to the user using `issue_assignees` table. + # For each issue iterated, use IssuesFinder to check if the issue should be counted. + initializer = IssueAssignee + .select(:issue_id).joins(", LATERAL (#{finder_constraint.to_sql}) as issues") + .where(user_id: @current_user.id) + .order(issue_id: :desc) + .limit(1) + recursive_finder = initializer.where("issue_assignees.issue_id < assigned_issues.issue_id") + + cte = <<~SQL + WITH RECURSIVE assigned_issues AS ( + ( + #{initializer.to_sql} + ) + UNION ALL + ( + SELECT next_assigned_issue.issue_id + FROM assigned_issues, + LATERAL ( + #{recursive_finder.to_sql} + ) next_assigned_issue + ) + ) SELECT COUNT(*) FROM (SELECT * FROM assigned_issues LIMIT #{@max_limit}) issues + SQL + + ApplicationRecord.connection.execute(cte).first["count"] + end + # rubocop: enable CodeReuse/ActiveRecord + + private + + # rubocop: disable CodeReuse/ActiveRecord + def finder_constraint + IssuesFinder.new(@current_user, assignee_id: @current_user.id, state: 'opened', non_archived: true) + .execute + .where("issues.id=issue_assignees.issue_id").limit(1) + end + # rubocop: enable CodeReuse/ActiveRecord + end +end diff --git a/app/services/users/banned_user_base_service.rb b/app/services/users/banned_user_base_service.rb index a582816283a..74c10581a6e 100644 --- a/app/services/users/banned_user_base_service.rb +++ b/app/services/users/banned_user_base_service.rb @@ -36,7 +36,7 @@ module Users end def log_event(user) - Gitlab::AppLogger.info(message: "User #{action}", user: "#{user.username}", email: "#{user.email}", "#{action}_by": "#{current_user.username}", ip_address: "#{current_user.current_sign_in_ip}") + Gitlab::AppLogger.info(message: "User #{action}", user: user.username.to_s, email: user.email.to_s, "#{action}_by": current_user.username.to_s, ip_address: current_user.current_sign_in_ip.to_s) end end end diff --git a/app/services/users/build_service.rb b/app/services/users/build_service.rb index 8ef1b3e0613..064bf132d3d 100644 --- a/app/services/users/build_service.rb +++ b/app/services/users/build_service.rb @@ -117,7 +117,7 @@ module Users end def skip_user_confirmation_email_from_setting - !Gitlab::CurrentSettings.send_user_confirmation_email + Gitlab::CurrentSettings.email_confirmation_setting_off? end def use_fallback_name? diff --git a/app/services/users/keys_count_service.rb b/app/services/users/keys_count_service.rb index f82d27eded9..378093f2e1b 100644 --- a/app/services/users/keys_count_service.rb +++ b/app/services/users/keys_count_service.rb @@ -11,7 +11,7 @@ module Users end def relation_for_count - user.keys + user.keys.auth end def raw? diff --git a/app/services/users/migrate_records_to_ghost_user_service.rb b/app/services/users/migrate_records_to_ghost_user_service.rb index 2d92aaed7da..5d518803315 100644 --- a/app/services/users/migrate_records_to_ghost_user_service.rb +++ b/app/services/users/migrate_records_to_ghost_user_service.rb @@ -42,6 +42,7 @@ module Users migrate_award_emoji migrate_snippets migrate_reviews + migrate_releases end def post_migrate_records @@ -96,6 +97,10 @@ module Users batched_migrate(Review, :author_id) end + def migrate_releases + batched_migrate(Release, :author_id) + end + # rubocop:disable CodeReuse/ActiveRecord def batched_migrate(base_scope, column, batch_size: 50) loop do diff --git a/app/services/users/reject_service.rb b/app/services/users/reject_service.rb index 459dd81b74d..dc22b2ec21d 100644 --- a/app/services/users/reject_service.rb +++ b/app/services/users/reject_service.rb @@ -34,7 +34,7 @@ module Users end def log_event(user) - Gitlab::AppLogger.info(message: "User instance access request rejected", user: "#{user.username}", email: "#{user.email}", rejected_by: "#{current_user.username}", ip_address: "#{current_user.current_sign_in_ip}") + Gitlab::AppLogger.info(message: "User instance access request rejected", user: user.username.to_s, email: user.email.to_s, rejected_by: current_user.username.to_s, ip_address: current_user.current_sign_in_ip.to_s) end end end diff --git a/app/services/users/update_highest_member_role_service.rb b/app/services/users/update_highest_member_role_service.rb index 90a5966265d..fff001e04d7 100644 --- a/app/services/users/update_highest_member_role_service.rb +++ b/app/services/users/update_highest_member_role_service.rb @@ -17,9 +17,7 @@ module Users private def user_highest_role - @user_highest_role ||= begin - @user.user_highest_role || @user.build_user_highest_role - end + @user_highest_role ||= @user.user_highest_role || @user.build_user_highest_role end def highest_access_level |