diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2017-08-07 12:07:42 +0300 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2017-08-22 07:33:20 +0300 |
commit | e7a060321fed61085c7d70d23e9ea33825d1467f (patch) | |
tree | e59b5fd808c21cd819ae62930839c29a99dc6ef9 /app/models/concerns/storage | |
parent | 72250a4ed8978b32c2e12dd05fc6feb8132e4083 (diff) |
Moving away from the "extend" based factory to a more traditional one.
Using `extend` dynamically can lead to bad performance as it
invalidates the method's cache.
Diffstat (limited to 'app/models/concerns/storage')
-rw-r--r-- | app/models/concerns/storage/hashed_project.rb | 72 | ||||
-rw-r--r-- | app/models/concerns/storage/legacy_project.rb | 73 |
2 files changed, 0 insertions, 145 deletions
diff --git a/app/models/concerns/storage/hashed_project.rb b/app/models/concerns/storage/hashed_project.rb deleted file mode 100644 index 292a73903b5..00000000000 --- a/app/models/concerns/storage/hashed_project.rb +++ /dev/null @@ -1,72 +0,0 @@ -module Storage - module HashedProject - extend ActiveSupport::Concern - - # Base directory - # - # @return [String] directory where repository is stored - def base_dir - %Q(#{disk_hash[0..1]}/#{disk_hash[2..3]}) if disk_hash - end - - # Disk path is used to build repository and project's wiki path on disk - # - # @return [String] combination of base_dir and the repository own name without `.git` or `.wiki.git` extensions - def disk_path - %Q(#{base_dir}/#{disk_hash}) - end - - def ensure_storage_path_exist - gitlab_shell.add_namespace(repository_storage_path, base_dir) - end - - def rename_repo - # TODO: We cannot wipe most of this method until we provide migration path for Container Registries - path_was = previous_changes['path'].first - old_path_with_namespace = File.join(namespace.full_path, path_was) - new_path_with_namespace = File.join(namespace.full_path, path) - - Rails.logger.error "Attempting to rename #{old_path_with_namespace} -> #{new_path_with_namespace}" - - if has_container_registry_tags? - Rails.logger.error "Project #{old_path_with_namespace} cannot be renamed because container registry tags are present!" - - # we currently doesn't support renaming repository if it contains images in container registry - raise StandardError.new('Project cannot be renamed, because images are present in its container registry') - end - - begin - # TODO: we can avoid cache expiration if cache is based on UUID or just project_id - expire_caches_before_rename(old_path_with_namespace) - expires_full_path_cache - - send_move_instructions(old_path_with_namespace) - - @old_path_with_namespace = old_path_with_namespace - - SystemHooksService.new.execute_hooks_for(self, :rename) - - @repository = nil - rescue => e - Rails.logger.error "Exception renaming #{old_path_with_namespace} -> #{new_path_with_namespace}: #{e}" - # Returning false does not rollback after_* transaction but gives - # us information about failing some of tasks - false - end - - Gitlab::AppLogger.info "Project was renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}" - - # TODO: When we move Uploads and Pages to use UUID we can disable this transfers as well - Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.full_path) - Gitlab::PagesTransfer.new.rename_project(path_was, path, namespace.full_path) - end - - private - - # Generates the hash for the project path and name on disk - # If you need to refer to the repository on disk, use the `#disk_path` - def disk_hash - @disk_hash ||= Digest::SHA2.hexdigest(self.id.to_s) if self.id - end - end -end diff --git a/app/models/concerns/storage/legacy_project.rb b/app/models/concerns/storage/legacy_project.rb deleted file mode 100644 index 839bbcc76ea..00000000000 --- a/app/models/concerns/storage/legacy_project.rb +++ /dev/null @@ -1,73 +0,0 @@ -module Storage - module LegacyProject - extend ActiveSupport::Concern - - # Base directory - # - # @return [String] directory where repository is stored - def base_dir - namespace.full_path - end - - # Disk path is used to build repository and project's wiki path on disk - # - # @return [String] combination of base_dir and the repository own name without `.git` or `.wiki.git` extensions - def disk_path - full_path - end - - def ensure_storage_path_exist - gitlab_shell.add_namespace(repository_storage_path, base_dir) - end - - def rename_repo - path_was = previous_changes['path'].first - old_path_with_namespace = File.join(namespace.full_path, path_was) - new_path_with_namespace = File.join(namespace.full_path, path) - - Rails.logger.error "Attempting to rename #{old_path_with_namespace} -> #{new_path_with_namespace}" - - if has_container_registry_tags? - Rails.logger.error "Project #{old_path_with_namespace} cannot be renamed because container registry tags are present!" - - # we currently doesn't support renaming repository if it contains images in container registry - raise StandardError.new('Project cannot be renamed, because images are present in its container registry') - end - - expire_caches_before_rename(old_path_with_namespace) - - if gitlab_shell.mv_repository(repository_storage_path, old_path_with_namespace, new_path_with_namespace) - # If repository moved successfully we need to send update instructions to users. - # However we cannot allow rollback since we moved repository - # So we basically we mute exceptions in next actions - begin - gitlab_shell.mv_repository(repository_storage_path, "#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki") - send_move_instructions(old_path_with_namespace) - expires_full_path_cache - - @old_path_with_namespace = old_path_with_namespace - - SystemHooksService.new.execute_hooks_for(self, :rename) - - @repository = nil - rescue => e - Rails.logger.error "Exception renaming #{old_path_with_namespace} -> #{new_path_with_namespace}: #{e}" - # Returning false does not rollback after_* transaction but gives - # us information about failing some of tasks - false - end - else - Rails.logger.error "Repository could not be renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}" - - # if we cannot move namespace directory we should rollback - # db changes in order to prevent out of sync between db and fs - raise StandardError.new('repository cannot be renamed') - end - - Gitlab::AppLogger.info "Project was renamed: #{old_path_with_namespace} -> #{new_path_with_namespace}" - - Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.full_path) - Gitlab::PagesTransfer.new.rename_project(path_was, path, namespace.full_path) - end - end -end |