diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-24 21:09:59 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-24 21:09:59 +0000 |
commit | 8a0ba602908b4360f52bf64fb715585d6245079e (patch) | |
tree | 0b9d005b11e26f2db40ce87d736abbb8fef7f755 /app/models | |
parent | e9322e019bfeb7f33ce4c17662d93e6579303c2b (diff) | |
download | gitlab-ce-8a0ba602908b4360f52bf64fb715585d6245079e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/cache_markdown_field.rb | 33 | ||||
-rw-r--r-- | app/models/concerns/mentionable.rb | 11 | ||||
-rw-r--r-- | app/models/note.rb | 8 |
3 files changed, 0 insertions, 52 deletions
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb index 3753a14ad40..9414d16beef 100644 --- a/app/models/concerns/cache_markdown_field.rb +++ b/app/models/concerns/cache_markdown_field.rb @@ -160,39 +160,6 @@ module CacheMarkdownField # We can only store mentions if the mentionable is a database object return unless self.is_a?(ApplicationRecord) - return store_mentions_without_subtransaction! if Feature.enabled?(:store_mentions_without_subtransaction, default_enabled: :yaml) - - refs = all_references(self.author) - - references = {} - references[:mentioned_users_ids] = refs.mentioned_user_ids.presence - references[:mentioned_groups_ids] = refs.mentioned_group_ids.presence - references[:mentioned_projects_ids] = refs.mentioned_project_ids.presence - - # One retry is enough as next time `model_user_mention` should return the existing mention record, - # that threw the `ActiveRecord::RecordNotUnique` exception in first place. - self.class.safe_ensure_unique(retries: 1) do # rubocop:disable Performance/ActiveRecordSubtransactionMethods - user_mention = model_user_mention - - # this may happen due to notes polymorphism, so noteable_id may point to a record - # that no longer exists as we cannot have FK on noteable_id - break if user_mention.blank? - - user_mention.mentioned_users_ids = references[:mentioned_users_ids] - user_mention.mentioned_groups_ids = references[:mentioned_groups_ids] - user_mention.mentioned_projects_ids = references[:mentioned_projects_ids] - - if user_mention.has_mentions? - user_mention.save! - else - user_mention.destroy! - end - end - - true - end - - def store_mentions_without_subtransaction! identifier = user_mention_identifier # this may happen due to notes polymorphism, so noteable_id may point to a record diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index 4df9e32d8ec..a0ea5ac8012 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -217,17 +217,6 @@ module Mentionable def user_mention_association association(:user_mentions).reflection end - - # User mention that is parsed from model description rather then its related notes. - # Models that have a description attribute like Issue, MergeRequest, Epic, Snippet may have such a user mention. - # Other mentionable models like Commit, DesignManagement::Design, will never have such record as those do not have - # a description attribute. - # - # Using this method followed by a call to *save* may result in *ActiveRecord::RecordNotUnique* exception - # in a multi-threaded environment. Make sure to use it within a *safe_ensure_unique* block. - def model_user_mention - user_mentions.where(note_id: nil).first_or_initialize - end end Mentionable.prepend_mod_with('Mentionable') diff --git a/app/models/note.rb b/app/models/note.rb index 58a00fe6fa1..6c5bbf36bd6 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -606,14 +606,6 @@ class Note < ApplicationRecord private - # Using this method followed by a call to *save* may result in *ActiveRecord::RecordNotUnique* exception - # in a multi-threaded environment. Make sure to use it within a *safe_ensure_unique* block. - def model_user_mention - return if user_mentions.is_a?(ActiveRecord::NullRelation) - - user_mentions.first_or_initialize - end - def system_note_viewable_by?(user) return true unless system_note_metadata |