diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-23 09:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-23 09:08:47 +0300 |
commit | d950ea420a77bc6b27037bd00484f2463e79b4fd (patch) | |
tree | ec93e370d6543321bb725e06f331b602e06873ac /app/models | |
parent | 9d9c8fc2ec2fdfa0bae2f77a5c2bde52a5bf45e2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/discussion.rb | 9 | ||||
-rw-r--r-- | app/models/environment.rb | 7 | ||||
-rw-r--r-- | app/models/note.rb | 7 |
3 files changed, 13 insertions, 10 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb index 076d8cc280c..203e14f1227 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -163,16 +163,15 @@ class Discussion end def cache_key - # Need this so cache will be invalidated when note within a discussion - # has been deleted. - notes_sha = Digest::SHA1.hexdigest(notes.map(&:id).join(':')) + # Need to use the notes' cache key so cache will be invalidated when note + # within a discussion has been deleted or has different data after post + # processing of content. + notes_sha = Digest::SHA1.hexdigest(notes.map(&:post_processed_cache_key).join(':')) [ CACHE_VERSION, - notes.last.latest_cached_markdown_version, id, notes_sha, - notes.max_by(&:updated_at).updated_at, resolved_at ].join(':') end diff --git a/app/models/environment.rb b/app/models/environment.rb index 558963c98c4..125218ea21d 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -5,6 +5,7 @@ class Environment < ApplicationRecord include ReactiveCaching include FastDestroyAll::Helpers include Presentable + include NullifyIfBlank self.reactive_cache_refresh_interval = 1.minute self.reactive_cache_lifetime = 55.seconds @@ -14,6 +15,7 @@ class Environment < ApplicationRecord belongs_to :project, required: true use_fast_destroy :all_deployments + nullify_if_blank :external_url has_many :all_deployments, class_name: 'Deployment' has_many :deployments, -> { visible } @@ -33,7 +35,6 @@ class Environment < ApplicationRecord has_one :upcoming_deployment, -> { running.distinct_on_environment }, class_name: 'Deployment', inverse_of: :environment has_one :latest_opened_most_severe_alert, -> { order_severity_with_open_prometheus_alert }, class_name: 'AlertManagement::Alert', inverse_of: :environment - before_validation :nullify_external_url before_validation :generate_slug, if: ->(env) { env.slug.blank? } before_save :set_environment_type @@ -230,10 +231,6 @@ class Environment < ApplicationRecord ref.to_s == last_deployment.try(:ref) end - def nullify_external_url - self.external_url = nil if self.external_url.blank? - end - def set_environment_type names = name.split('/') diff --git a/app/models/note.rb b/app/models/note.rb index ed341e58436..b31b1a20cd8 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -586,6 +586,13 @@ class Note < ApplicationRecord review.present? || !author.can_trigger_notifications? end + def post_processed_cache_key + cache_key_items = [cache_key] + cache_key_items << Digest::SHA1.hexdigest(redacted_note_html) if redacted_note_html.present? + + cache_key_items.join(':') + end + private # Using this method followed by a call to *save* may result in *ActiveRecord::RecordNotUnique* exception |