Class: Gitlab::Cleanup::OrphanLfsFileReferences

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/cleanup/orphan_lfs_file_references.rb

Constant Summary collapse

DEFAULT_REMOVAL_LIMIT =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(project, dry_run: true, logger: nil, limit: nil) ⇒ OrphanLfsFileReferences

Returns a new instance of OrphanLfsFileReferences.


12
13
14
15
16
17
# File 'lib/gitlab/cleanup/orphan_lfs_file_references.rb', line 12

def initialize(project, dry_run: true, logger: nil, limit: nil)
  @project = project
  @dry_run = dry_run
  @logger = logger || Gitlab::AppLogger
  @limit = limit
end

Instance Attribute Details

#dry_runObject (readonly)

Returns the value of attribute dry_run


8
9
10
# File 'lib/gitlab/cleanup/orphan_lfs_file_references.rb', line 8

def dry_run
  @dry_run
end

#limitObject (readonly)

Returns the value of attribute limit


8
9
10
# File 'lib/gitlab/cleanup/orphan_lfs_file_references.rb', line 8

def limit
  @limit
end

#loggerObject (readonly)

Returns the value of attribute logger


8
9
10
# File 'lib/gitlab/cleanup/orphan_lfs_file_references.rb', line 8

def logger
  @logger
end

#projectObject (readonly)

Returns the value of attribute project


8
9
10
# File 'lib/gitlab/cleanup/orphan_lfs_file_references.rb', line 8

def project
  @project
end

Instance Method Details

#run!Object


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/cleanup/orphan_lfs_file_references.rb', line 19

def run!
  # If this project is an LFS storage project (e.g. is the root of a fork
  # network), what it is safe to remove depends on the sum of its forks.
  # For now, skip cleaning up LFS for this complicated case
  if project.forks_count > 0 && project.lfs_storage_project == project
    log_info("Skipping orphan LFS check for #{project.name_with_namespace} as it is a fork root")
    return
  end

  log_info("Looking for orphan LFS files for project #{project.name_with_namespace}")

  remove_orphan_references
end