diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/issues/base_service.rb | 12 | ||||
-rw-r--r-- | app/services/issues/close_service.rb | 2 | ||||
-rw-r--r-- | app/services/issues/create_service.rb | 1 | ||||
-rw-r--r-- | app/services/issues/reopen_service.rb | 1 | ||||
-rw-r--r-- | app/services/issues/update_service.rb | 20 | ||||
-rw-r--r-- | app/services/metrics/dashboard/base_embed_service.rb | 4 | ||||
-rw-r--r-- | app/services/metrics/dashboard/custom_metric_embed_service.rb | 2 | ||||
-rw-r--r-- | app/services/metrics/dashboard/default_embed_service.rb | 2 | ||||
-rw-r--r-- | app/services/metrics/dashboard/dynamic_embed_service.rb | 2 | ||||
-rw-r--r-- | app/services/metrics/dashboard/grafana_metric_embed_service.rb | 4 | ||||
-rw-r--r-- | app/services/milestones/closed_issues_count_service.rb | 17 | ||||
-rw-r--r-- | app/services/milestones/issues_count_service.rb | 17 | ||||
-rw-r--r-- | app/services/milestones/transfer_service.rb | 18 | ||||
-rw-r--r-- | app/services/post_receive_service.rb | 16 |
14 files changed, 103 insertions, 15 deletions
diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index 974f7e598ca..9e72f6dad8d 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -34,6 +34,18 @@ module Issues def update_project_counter_caches?(issue) super || issue.confidential_changed? end + + def delete_milestone_closed_issue_counter_cache(milestone) + return unless milestone + + Milestones::ClosedIssuesCountService.new(milestone).delete_cache + end + + def delete_milestone_total_issue_counter_cache(milestone) + return unless milestone + + Milestones::IssuesCountService.new(milestone).delete_cache + end end end diff --git a/app/services/issues/close_service.rb b/app/services/issues/close_service.rb index ce955b07648..21e9a2210fb 100644 --- a/app/services/issues/close_service.rb +++ b/app/services/issues/close_service.rb @@ -38,6 +38,8 @@ module Issues issue.update_project_counter_caches store_first_mentioned_in_commit_at(issue, closed_via) if closed_via.is_a?(MergeRequest) + + delete_milestone_closed_issue_counter_cache(issue.milestone) end issue diff --git a/app/services/issues/create_service.rb b/app/services/issues/create_service.rb index e8879d4df66..7869509aa9c 100644 --- a/app/services/issues/create_service.rb +++ b/app/services/issues/create_service.rb @@ -29,6 +29,7 @@ module Issues todo_service.new_issue(issuable, current_user) user_agent_detail_service.create resolve_discussions_with_issue(issuable) + delete_milestone_total_issue_counter_cache(issuable.milestone) super end diff --git a/app/services/issues/reopen_service.rb b/app/services/issues/reopen_service.rb index 56d59b235a7..0ffe33dd317 100644 --- a/app/services/issues/reopen_service.rb +++ b/app/services/issues/reopen_service.rb @@ -12,6 +12,7 @@ module Issues execute_hooks(issue, 'reopen') invalidate_cache_counts(issue, users: issue.assignees) issue.update_project_counter_caches + delete_milestone_closed_issue_counter_cache(issue.milestone) end issue diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index 68d1657d881..78ebbd7bff2 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -115,10 +115,26 @@ module Issues end def handle_milestone_change(issue) - return if skip_milestone_email - return unless issue.previous_changes.include?('milestone_id') + invalidate_milestone_issue_counters(issue) + send_milestone_change_notification(issue) + end + + def invalidate_milestone_issue_counters(issue) + issue.previous_changes['milestone_id'].each do |milestone_id| + next unless milestone_id + + milestone = Milestone.find_by_id(milestone_id) + + delete_milestone_closed_issue_counter_cache(milestone) + delete_milestone_total_issue_counter_cache(milestone) + end + end + + def send_milestone_change_notification(issue) + return if skip_milestone_email + if issue.milestone.nil? notification_service.async.removed_milestone_issue(issue, current_user) else diff --git a/app/services/metrics/dashboard/base_embed_service.rb b/app/services/metrics/dashboard/base_embed_service.rb index 8aef9873ac1..4c7fa454460 100644 --- a/app/services/metrics/dashboard/base_embed_service.rb +++ b/app/services/metrics/dashboard/base_embed_service.rb @@ -5,6 +5,10 @@ module Metrics module Dashboard class BaseEmbedService < ::Metrics::Dashboard::BaseService + def self.embedded?(embed_param) + ActiveModel::Type::Boolean.new.cast(embed_param) + end + def cache_key "dynamic_metrics_dashboard_#{identifiers}" end diff --git a/app/services/metrics/dashboard/custom_metric_embed_service.rb b/app/services/metrics/dashboard/custom_metric_embed_service.rb index 9e616f4e379..456074ae6ad 100644 --- a/app/services/metrics/dashboard/custom_metric_embed_service.rb +++ b/app/services/metrics/dashboard/custom_metric_embed_service.rb @@ -18,7 +18,7 @@ module Metrics # custom metrics from the DB. def valid_params?(params) [ - params[:embedded], + embedded?(params[:embedded]), valid_dashboard?(params[:dashboard_path]), valid_group_title?(params[:group]), params[:title].present?, diff --git a/app/services/metrics/dashboard/default_embed_service.rb b/app/services/metrics/dashboard/default_embed_service.rb index 39f7c3943dd..30a8150d6be 100644 --- a/app/services/metrics/dashboard/default_embed_service.rb +++ b/app/services/metrics/dashboard/default_embed_service.rb @@ -22,7 +22,7 @@ module Metrics class << self def valid_params?(params) - params[:embedded].present? + embedded?(params[:embedded]) end end diff --git a/app/services/metrics/dashboard/dynamic_embed_service.rb b/app/services/metrics/dashboard/dynamic_embed_service.rb index db5b7c9e32a..ff540c30579 100644 --- a/app/services/metrics/dashboard/dynamic_embed_service.rb +++ b/app/services/metrics/dashboard/dynamic_embed_service.rb @@ -22,7 +22,7 @@ module Metrics # for additional info on defining custom dashboards. def valid_params?(params) [ - params[:embedded], + embedded?(params[:embedded]), params[:group].present?, params[:title].present?, params[:y_label] diff --git a/app/services/metrics/dashboard/grafana_metric_embed_service.rb b/app/services/metrics/dashboard/grafana_metric_embed_service.rb index 44b58ad9729..3ad3a2c609e 100644 --- a/app/services/metrics/dashboard/grafana_metric_embed_service.rb +++ b/app/services/metrics/dashboard/grafana_metric_embed_service.rb @@ -6,7 +6,7 @@ # Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards. module Metrics module Dashboard - class GrafanaMetricEmbedService < ::Metrics::Dashboard::BaseService + class GrafanaMetricEmbedService < ::Metrics::Dashboard::BaseEmbedService include ReactiveCaching SEQUENCE = [ @@ -24,7 +24,7 @@ module Metrics # to uniquely identify a grafana dashboard. def valid_params?(params) [ - params[:embedded], + embedded?(params[:embedded]), params[:grafana_url] ].all? end diff --git a/app/services/milestones/closed_issues_count_service.rb b/app/services/milestones/closed_issues_count_service.rb new file mode 100644 index 00000000000..80aab235e49 --- /dev/null +++ b/app/services/milestones/closed_issues_count_service.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Milestones + class ClosedIssuesCountService < BaseCountService + def initialize(milestone) + @milestone = milestone + end + + def cache_key + "milestone_closed_issues_count_#{@milestone.milestoneish_id}" + end + + def relation_for_count + @milestone.issues.closed + end + end +end diff --git a/app/services/milestones/issues_count_service.rb b/app/services/milestones/issues_count_service.rb new file mode 100644 index 00000000000..f8b80fa9aef --- /dev/null +++ b/app/services/milestones/issues_count_service.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Milestones + class IssuesCountService < BaseCountService + def initialize(milestone) + @milestone = milestone + end + + def cache_key + "milestone_total_issues_count_#{@milestone.milestoneish_id}" + end + + def relation_for_count + @milestone.issues + end + end +end diff --git a/app/services/milestones/transfer_service.rb b/app/services/milestones/transfer_service.rb index 1efbfed4853..213c6f8f1dd 100644 --- a/app/services/milestones/transfer_service.rb +++ b/app/services/milestones/transfer_service.rb @@ -22,7 +22,7 @@ module Milestones milestones_to_transfer.find_each do |milestone| new_milestone = find_or_create_milestone(milestone) - update_issues_milestone(milestone.id, new_milestone&.id) + update_issues_milestone(milestone, new_milestone) update_merge_requests_milestone(milestone.id, new_milestone&.id) end end @@ -68,9 +68,12 @@ module Milestones end # rubocop: disable CodeReuse/ActiveRecord - def update_issues_milestone(old_milestone_id, new_milestone_id) - Issue.where(project: project, milestone_id: old_milestone_id) - .update_all(milestone_id: new_milestone_id) + def update_issues_milestone(old_milestone, new_milestone) + Issue.where(project: project, milestone_id: old_milestone.id) + .update_all(milestone_id: new_milestone&.id) + + delete_milestone_issues_caches(old_milestone) + delete_milestone_issues_caches(new_milestone) end # rubocop: enable CodeReuse/ActiveRecord @@ -80,5 +83,12 @@ module Milestones .update_all(milestone_id: new_milestone_id) end # rubocop: enable CodeReuse/ActiveRecord + + def delete_milestone_issues_caches(milestone) + return unless milestone + + Milestones::IssuesCountService.new(milestone).delete_cache + Milestones::ClosedIssuesCountService.new(milestone).delete_cache + end end end diff --git a/app/services/post_receive_service.rb b/app/services/post_receive_service.rb index bc5ec22e77f..f12e45d701a 100644 --- a/app/services/post_receive_service.rb +++ b/app/services/post_receive_service.rb @@ -4,10 +4,11 @@ # # Used for scheduling related jobs after a push action has been performed class PostReceiveService - attr_reader :user, :project, :params + attr_reader :user, :repository, :project, :params - def initialize(user, project, params) + def initialize(user, repository, project, params) @user = user + @repository = repository @project = project @params = params end @@ -24,7 +25,7 @@ class PostReceiveService mr_options = push_options.get(:merge_request) if mr_options.present? - message = process_mr_push_options(mr_options, project, user, params[:changes]) + message = process_mr_push_options(mr_options, params[:changes]) response.add_alert_message(message) end @@ -46,8 +47,13 @@ class PostReceiveService response end - def process_mr_push_options(push_options, project, user, changes) + def process_mr_push_options(push_options, changes) Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/61359') + return unless repository + + unless repository.repo_type.project? + return push_options_warning('Push options are only supported for projects') + end service = ::MergeRequests::PushOptionsHandlerService.new( project, user, changes, push_options @@ -64,6 +70,8 @@ class PostReceiveService end def merge_request_urls + return [] unless repository&.repo_type&.project? + ::MergeRequests::GetUrlsService.new(project).execute(params[:changes]) end end |