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 ResetOnUnionError

ResetOnUnionError::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, 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 SensitiveSerializableHash

#serializable_hash

Class Method Details

.calculate_oid(path) ⇒ Object



58
59
60
# File 'app/models/lfs_object.rb', line 58

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) ⇒ Object



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

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

.unreferenced_in_batchesObject



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

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)


43
44
45
# File 'app/models/lfs_object.rb', line 43

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

#project_allowed_access?(project) ⇒ Boolean

Returns:

  • (Boolean)


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

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