diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2019-04-20 16:27:53 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-04-20 16:27:53 +0300 |
commit | a02e22438de38e4eca64e45c324af10626b3975c (patch) | |
tree | e4b6118887e52c14e9c8847de7eb9b1cb38b523e /app | |
parent | 9c2b37d7c4621f8284530565fa1d361b12502715 (diff) |
Fix wrong use of ActiveRecord in PoolRepository
Diffstat (limited to 'app')
-rw-r--r-- | app/models/pool_repository.rb | 5 | ||||
-rw-r--r-- | app/models/project.rb | 8 |
2 files changed, 6 insertions, 7 deletions
diff --git a/app/models/pool_repository.rb b/app/models/pool_repository.rb index 7934118761e..50eed7344bd 100644 --- a/app/models/pool_repository.rb +++ b/app/models/pool_repository.rb @@ -7,7 +7,7 @@ class PoolRepository < ApplicationRecord include Shardable include AfterCommitQueue - has_one :source_project, class_name: 'Project' + belongs_to :source_project, class_name: 'Project' validates :source_project, presence: true has_many :member_projects, class_name: 'Project' @@ -99,7 +99,8 @@ class PoolRepository < ApplicationRecord end def inspect - "#<#{self.class.name} id:#{id} state:#{state} disk_path:#{disk_path} source_project: #{source_project.full_path}>" + source = source_project ? source_project.full_path : 'nil' + "#<#{self.class.name} id:#{id} state:#{state} disk_path:#{disk_path} source_project: #{source}>" end private diff --git a/app/models/project.rb b/app/models/project.rb index 2fb6f5cb6a7..b7a10b3547a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -2131,13 +2131,11 @@ class Project < ApplicationRecord end def create_new_pool_repository - pool = begin - create_pool_repository!(shard: Shard.by_name(repository_storage), source_project: self) - rescue ActiveRecord::RecordNotUnique - pool_repository(true) - end + pool = PoolRepository.safe_find_or_create_by!(shard: Shard.by_name(repository_storage), source_project: self) + update!(pool_repository: pool) pool.schedule unless pool.scheduled? + pool end |