Class: LfsObject

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, Checksummable, EachBatch, FileStoreMounter
Defined in:
app/models/lfs_object.rb

Constant Summary collapse

BATCH_SIZE =
3000

Constants included from FileStoreMounter

FileStoreMounter::ALLOWED_FILE_FIELDS

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.calculate_oid(path) ⇒ Object



60
61
62
# File 'app/models/lfs_object.rb', line 60

def self.calculate_oid(path)
  self.sha256_hexdigest(path)
end

.for_oid_and_size(oid, size) ⇒ Object



22
23
24
# File 'app/models/lfs_object.rb', line 22

def self.for_oid_and_size(oid, size)
  find_by(oid: oid, size: size)
end

.not_linked_to_project(project, repository_type: nil) ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/models/lfs_object.rb', line 26

def self.not_linked_to_project(project, repository_type: nil)
  linked_to_project = project.lfs_objects_projects.where('lfs_objects_projects.lfs_object_id = lfs_objects.id')
  linked_to_project = linked_to_project.where(repository_type: repository_type) if repository_type
  where(
    'NOT EXISTS (?)',
    linked_to_project.select(1)
  )
end

.unreferenced_in_batchesObject



49
50
51
52
53
54
55
56
57
58
# File 'app/models/lfs_object.rb', line 49

def self.unreferenced_in_batches
  each_batch(of: BATCH_SIZE, order: :desc) do |lfs_objects|
    relation = lfs_objects.where(
      'NOT EXISTS (?)',
      LfsObjectsProject.select(1).where('lfs_objects_projects.lfs_object_id = lfs_objects.id')
    )

    yield relation if relation.any?
  end
end

Instance Method Details

#local_store?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/lfs_object.rb', line 45

def local_store?
  file_store == LfsObjectUploader::Store::LOCAL
end

#project_allowed_access?(project) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# File 'app/models/lfs_object.rb', line 35

def project_allowed_access?(project)
  if project.fork_network_member
    lfs_objects_projects
      .where("EXISTS(?)", project.fork_network.fork_network_members.select(1).where("fork_network_members.project_id = lfs_objects_projects.project_id"))
      .exists?
  else
    lfs_objects_projects.where(project_id: project.id).exists?
  end
end