Class: Projects::CleanupService

Inherits:
BaseService show all
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

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseService

#initialize

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

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#executeObject

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


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/projects/cleanup_service.rb', line 21

def execute
  apply_bfg_object_map!

  # Remove older objects that are no longer referenced
  GitGarbageCollectWorker.new.perform(project.id, :gc, "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

  project.bfg_object_map.remove!
end