Class: Projects::CleanupService
- Inherits:
-
BaseService
- Object
- BaseService
- Projects::CleanupService
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/projects/cleanup_service.rb
Overview
The CleanupService removes data from the project repository following a BFG rewrite: rtyley.github.io/bfg-repo-cleaner/
Before executing this service, all refs rewritten by BFG should have been pushed to the repository
Constant Summary collapse
- NoUploadError =
StandardError.new("Couldn't find uploaded object map")
Instance Attribute Summary
Attributes inherited from BaseService
#current_user, #params, #project
Class Method Summary collapse
Instance Method Summary collapse
-
#execute ⇒ Object
Attempt to clean up the project following the push.
Methods inherited from BaseService
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
This class inherits a constructor from BaseService
Class Method Details
.cleanup_after(project) ⇒ Object
26 27 28 29 |
# File 'app/services/projects/cleanup_service.rb', line 26 def cleanup_after(project) project.bfg_object_map.remove! project.set_repository_writable! end |
.enqueue(project, current_user, bfg_object_map) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/projects/cleanup_service.rb', line 15 def enqueue(project, current_user, bfg_object_map) Projects::UpdateService.new(project, current_user, bfg_object_map: bfg_object_map).execute.tap do |result| next unless result[:status] == :success project.set_repository_read_only! RepositoryCleanupWorker.perform_async(project.id, current_user.id) end rescue Project::RepositoryReadOnlyError => err { status: :error, message: (_('Failed to make repository read-only: %{reason}') % { reason: err. }) } end |
Instance Method Details
#execute ⇒ Object
Attempt to clean up the project following the push. Warning: this is destructive!
path is the path of an upload of a BFG object map file. It contains a line per rewritten object, with the old and new SHAs space-separated. It can be used to update or remove content that references the objects that BFG has altered
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/projects/cleanup_service.rb', line 39 def execute apply_bfg_object_map! # Remove older objects that are no longer referenced Projects::GitGarbageCollectWorker.new.perform(project.id, :prune, "project_cleanup:gc:#{project.id}") # The cache may now be inaccurate, and holding onto it could prevent # bugs assuming the presence of some object from manifesting for some # time. Better to feel the pain immediately. project.repository.expire_all_method_caches self.class.cleanup_after(project) end |