summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 15:09:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 15:09:30 +0000
commitc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (patch)
tree967afee9a510ff9dd503ebd83706dc760ec2e3ed /app/models
parent903ccf7c93eb9490c76857bffe744249cc07de09 (diff)
downloadgitlab-ce-c6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/has_repository.rb17
-rw-r--r--app/models/concerns/update_highest_role.rb38
-rw-r--r--app/models/concerns/versioned_description.rb1
-rw-r--r--app/models/member.rb20
-rw-r--r--app/models/project_wiki.rb6
-rw-r--r--app/models/snippet.rb8
-rw-r--r--app/models/user.rb21
7 files changed, 63 insertions, 48 deletions
diff --git a/app/models/concerns/has_repository.rb b/app/models/concerns/has_repository.rb
index 6a09741b903..af7afd6604a 100644
--- a/app/models/concerns/has_repository.rb
+++ b/app/models/concerns/has_repository.rb
@@ -87,26 +87,15 @@ module HasRepository
end
def url_to_repo
- Gitlab::Shell.url_to_repo(full_path)
+ ssh_url_to_repo
end
def ssh_url_to_repo
- url_to_repo
+ Gitlab::RepositoryUrlBuilder.build(repository.full_path, protocol: :ssh)
end
def http_url_to_repo
- custom_root = Gitlab::CurrentSettings.custom_http_clone_url_root
-
- url = if custom_root.present?
- Gitlab::Utils.append_path(
- custom_root,
- web_url(only_path: true)
- )
- else
- web_url
- end
-
- "#{url}.git"
+ Gitlab::RepositoryUrlBuilder.build(repository.full_path, protocol: :http)
end
def web_url(only_path: nil)
diff --git a/app/models/concerns/update_highest_role.rb b/app/models/concerns/update_highest_role.rb
new file mode 100644
index 00000000000..7efc436c6c8
--- /dev/null
+++ b/app/models/concerns/update_highest_role.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module UpdateHighestRole
+ extend ActiveSupport::Concern
+
+ HIGHEST_ROLE_LEASE_TIMEOUT = 10.minutes.to_i
+ HIGHEST_ROLE_JOB_DELAY = 10.minutes
+
+ included do
+ after_commit :update_highest_role
+ end
+
+ private
+
+ # Schedule a Sidekiq job to update the highest role for a User
+ #
+ # The job will be called outside of a transaction in order to ensure the changes
+ # to be commited before attempting to update the highest role.
+ # The exlusive lease will not be released after completion to prevent multiple jobs
+ # being executed during the defined timeout.
+ def update_highest_role
+ return unless update_highest_role?
+
+ run_after_commit_or_now do
+ lease_key = "update_highest_role:#{update_highest_role_attribute}"
+ lease = Gitlab::ExclusiveLease.new(lease_key, timeout: HIGHEST_ROLE_LEASE_TIMEOUT)
+
+ if lease.try_obtain
+ UpdateHighestRoleWorker.perform_in(HIGHEST_ROLE_JOB_DELAY, update_highest_role_attribute)
+ else
+ # use same logging as ExclusiveLeaseGuard
+ # rubocop:disable Gitlab/RailsLogger
+ Rails.logger.error('Cannot obtain an exclusive lease. There must be another instance already in execution.')
+ # rubocop:enable Gitlab/RailsLogger
+ end
+ end
+ end
+end
diff --git a/app/models/concerns/versioned_description.rb b/app/models/concerns/versioned_description.rb
index ee8d2d45357..dd602efea1c 100644
--- a/app/models/concerns/versioned_description.rb
+++ b/app/models/concerns/versioned_description.rb
@@ -16,7 +16,6 @@ module VersionedDescription
def save_description_version
self.saved_description_version = nil
- return unless Feature.enabled?(:save_description_versions, issuing_parent, default_enabled: true)
return unless saved_change_to_description?
unless description_versions.exists?
diff --git a/app/models/member.rb b/app/models/member.rb
index d7c515b650b..5b33333aa23 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -9,6 +9,7 @@ class Member < ApplicationRecord
include Presentable
include Gitlab::Utils::StrongMemoize
include FromUnion
+ include UpdateHighestRole
attr_accessor :raw_invite_token
@@ -100,7 +101,6 @@ class Member < ApplicationRecord
after_destroy :destroy_notification_setting
after_destroy :post_destroy_hook, unless: :pending?
after_commit :refresh_member_authorized_projects
- after_commit :update_highest_role
default_value_for :notification_level, NotificationSetting.levels[:global]
@@ -463,21 +463,15 @@ class Member < ApplicationRecord
end
end
- # Triggers the service to schedule a Sidekiq job to update the highest role
- # for a User
- #
- # The job will be called outside of a transaction in order to ensure the changes
- # for a Member to be commited before attempting to update the highest role.
- # rubocop: disable CodeReuse/ServiceClass
- def update_highest_role
+ def update_highest_role?
return unless user_id.present?
- return unless previous_changes[:access_level].present?
- run_after_commit_or_now do
- Members::UpdateHighestRoleService.new(user_id).execute
- end
+ previous_changes[:access_level].present?
+ end
+
+ def update_highest_role_attribute
+ user_id
end
- # rubocop: enable CodeReuse/ServiceClass
end
Member.prepend_if_ee('EE::Member')
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index 4b888648b9e..708b45cf5f0 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -49,15 +49,15 @@ class ProjectWiki
end
def url_to_repo
- Gitlab::Shell.url_to_repo(full_path)
+ ssh_url_to_repo
end
def ssh_url_to_repo
- url_to_repo
+ Gitlab::RepositoryUrlBuilder.build(repository.full_path, protocol: :ssh)
end
def http_url_to_repo
- @project.http_url_to_repo.sub(%r{git\z}, 'wiki.git')
+ Gitlab::RepositoryUrlBuilder.build(repository.full_path, protocol: :http)
end
def wiki_base_path
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index cfe1c77ec48..821de70f9d9 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -258,10 +258,12 @@ class Snippet < ApplicationRecord
super
end
+ override :repository
def repository
@repository ||= Repository.new(full_path, self, shard: repository_storage, disk_path: disk_path, repo_type: Gitlab::GlRepository::SNIPPET)
end
+ override :repository_size_checker
def repository_size_checker
strong_memoize(:repository_size_checker) do
::Gitlab::RepositorySizeChecker.new(
@@ -271,6 +273,7 @@ class Snippet < ApplicationRecord
end
end
+ override :storage
def storage
@storage ||= Storage::Hashed.new(self, prefix: Storage::Hashed::SNIPPET_REPOSITORY_PATH_PREFIX)
end
@@ -278,6 +281,7 @@ class Snippet < ApplicationRecord
# This is the full_path used to identify the
# the snippet repository. It will be used mostly
# for logging purposes.
+ override :full_path
def full_path
return unless persisted?
@@ -290,10 +294,6 @@ class Snippet < ApplicationRecord
end
end
- def url_to_repo
- Gitlab::Shell.url_to_repo(full_path.delete('@'))
- end
-
def repository_storage
snippet_repository&.shard_name || self.class.pick_repository_storage
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 68c52751804..42972477d97 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -23,6 +23,7 @@ class User < ApplicationRecord
include BatchDestroyDependentAssociations
include HasUniqueInternalUsers
include IgnorableColumns
+ include UpdateHighestRole
DEFAULT_NOTIFICATION_LEVEL = :participating
@@ -238,7 +239,6 @@ class User < ApplicationRecord
end
end
end
- after_commit :update_highest_role, on: [:create, :update]
after_initialize :set_projects_limit
@@ -1854,20 +1854,15 @@ class User < ApplicationRecord
last_active_at.to_i <= MINIMUM_INACTIVE_DAYS.days.ago.to_i
end
- # Triggers the service to schedule a Sidekiq job to update the highest role
- # for a User
- #
- # The job will be called outside of a transaction in order to ensure the changes
- # for a Member to be commited before attempting to update the highest role.
- # rubocop: disable CodeReuse/ServiceClass
- def update_highest_role
- return unless (previous_changes.keys & %w(state user_type ghost)).any?
+ def update_highest_role?
+ return false unless persisted?
- run_after_commit_or_now do
- Members::UpdateHighestRoleService.new(id).execute
- end
+ (previous_changes.keys & %w(state user_type ghost)).any?
+ end
+
+ def update_highest_role_attribute
+ id
end
- # rubocop: enable CodeReuse/ServiceClass
end
User.prepend_if_ee('EE::User')