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

Constructor Details

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

Returns a new instance of OrphanLfsFileReferences.



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

def initialize(project, dry_run: true, logger: nil)
  @project = project
  @dry_run = dry_run
  @logger = logger || Gitlab::AppLogger
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

#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



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

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

  if project.lfs_objects.empty?
    log_info("Project #{project.name_with_namespace} is linked to 0 LFS objects. Nothing to do")
    return
  end

  remove_orphan_references
end