Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-07 03:08:34 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-07 03:08:34 +0300
commit7e89568aa1b1c531aa34860fbd9e77d9e988b9b2 (patch)
tree9d644d947b75594d969f040ef046541c769e0dc3 /app/models
parentf2143c9986ad7b6206b8a41cc9aeb419e543d3f5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/integrations/base_slack_notification.rb1
-rw-r--r--app/models/integrations/jira.rb1
-rw-r--r--app/models/project.rb32
-rw-r--r--app/models/project_export_job.rb14
4 files changed, 45 insertions, 3 deletions
diff --git a/app/models/integrations/base_slack_notification.rb b/app/models/integrations/base_slack_notification.rb
index cbfcb1807f0..7a2a91aa0d2 100644
--- a/app/models/integrations/base_slack_notification.rb
+++ b/app/models/integrations/base_slack_notification.rb
@@ -57,6 +57,7 @@ module Integrations
label: Integration::SNOWPLOW_EVENT_LABEL,
property: key,
user: User.find(user_id),
+ context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: key).to_context],
**optional_arguments
)
end
diff --git a/app/models/integrations/jira.rb b/app/models/integrations/jira.rb
index 7945e185e8c..45302a0bd09 100644
--- a/app/models/integrations/jira.rb
+++ b/app/models/integrations/jira.rb
@@ -404,6 +404,7 @@ module Integrations
label: Integration::SNOWPLOW_EVENT_LABEL,
property: key,
user: user,
+ context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: key).to_context],
**optional_arguments
)
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 5d66e7d2854..bb266d86cdb 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -265,10 +265,24 @@ class Project < ApplicationRecord
has_many :incident_management_issuable_escalation_statuses, through: :issues, inverse_of: :project, class_name: 'IncidentManagement::IssuableEscalationStatus'
has_many :incident_management_timeline_event_tags, inverse_of: :project, class_name: 'IncidentManagement::TimelineEventTag'
has_many :labels, class_name: 'ProjectLabel'
- has_many :integrations
has_many :events
has_many :milestones
+ has_many :integrations
+ has_many :alert_hooks_integrations, -> { alert_hooks }, class_name: 'Integration'
+ has_many :archive_trace_hooks_integrations, -> { archive_trace_hooks }, class_name: 'Integration'
+ has_many :confidential_issue_hooks_integrations, -> { confidential_issue_hooks }, class_name: 'Integration'
+ has_many :confidential_note_hooks_integrations, -> { confidential_note_hooks }, class_name: 'Integration'
+ has_many :deployment_hooks_integrations, -> { deployment_hooks }, class_name: 'Integration'
+ has_many :issue_hooks_integrations, -> { issue_hooks }, class_name: 'Integration'
+ has_many :job_hooks_integrations, -> { job_hooks }, class_name: 'Integration'
+ has_many :merge_request_hooks_integrations, -> { merge_request_hooks }, class_name: 'Integration'
+ has_many :note_hooks_integrations, -> { note_hooks }, class_name: 'Integration'
+ has_many :pipeline_hooks_integrations, -> { pipeline_hooks }, class_name: 'Integration'
+ has_many :push_hooks_integrations, -> { push_hooks }, class_name: 'Integration'
+ has_many :tag_push_hooks_integrations, -> { tag_push_hooks }, class_name: 'Integration'
+ has_many :wiki_page_hooks_integrations, -> { wiki_page_hooks }, class_name: 'Integration'
+
# Projects with a very large number of notes may time out destroying them
# through the foreign key. Additionally, the deprecated attachment uploader
# for notes requires us to use dependent: :destroy to avoid orphaning uploaded
@@ -1713,8 +1727,14 @@ class Project < ApplicationRecord
def execute_integrations(data, hooks_scope = :push_hooks)
# Call only service hooks that are active for this scope
run_after_commit_or_now do
- integrations.public_send(hooks_scope).each do |integration| # rubocop:disable GitlabSecurity/PublicSend
- integration.async_execute(data)
+ if use_integration_relations?
+ association("#{hooks_scope}_integrations").reader.each do |integration|
+ integration.async_execute(data)
+ end
+ else
+ integrations.public_send(hooks_scope).each do |integration| # rubocop:disable GitlabSecurity/PublicSend
+ integration.async_execute(data)
+ end
end
end
end
@@ -3347,6 +3367,12 @@ class Project < ApplicationRecord
ProjectFeature::PRIVATE
end
end
+
+ def use_integration_relations?
+ strong_memoize(:use_integration_relations) do
+ Feature.enabled?(:cache_project_integrations, self)
+ end
+ end
end
Project.prepend_mod_with('Project')
diff --git a/app/models/project_export_job.rb b/app/models/project_export_job.rb
index 47be692d57a..d26ce5465cd 100644
--- a/app/models/project_export_job.rb
+++ b/app/models/project_export_job.rb
@@ -1,6 +1,10 @@
# frozen_string_literal: true
class ProjectExportJob < ApplicationRecord
+ include EachBatch
+
+ EXPIRES_IN = 7.days
+
belongs_to :project
has_many :relation_exports, class_name: 'Projects::ImportExport::RelationExport'
@@ -13,6 +17,8 @@ class ProjectExportJob < ApplicationRecord
failed: 3
}.freeze
+ scope :prunable, -> { where("updated_at < ?", EXPIRES_IN.ago) }
+
state_machine :status, initial: :queued do
event :start do
transition [:queued] => :started
@@ -31,4 +37,12 @@ class ProjectExportJob < ApplicationRecord
state :finished, value: STATUS[:finished]
state :failed, value: STATUS[:failed]
end
+
+ class << self
+ def prune_expired_jobs
+ prunable.each_batch do |relation| # rubocop:disable Style/SymbolProc
+ relation.delete_all
+ end
+ end
+ end
end