Class: LfsObject

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

Constant Summary collapse

BATCH_SIZE =
3000

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileStoreMounter

#store_file_now!, #update_file_store

Methods included from ObjectStorage::BackgroundMove

#background_upload, #changed_mounts

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


52
53
54
# File 'app/models/lfs_object.rb', line 52

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

.not_linked_to_project(project) ⇒ Object


24
25
26
27
# File 'app/models/lfs_object.rb', line 24

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


43
44
45
46
47
48
49
50
# File 'app/models/lfs_object.rb', line 43

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)

39
40
41
# File 'app/models/lfs_object.rb', line 39

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

#project_allowed_access?(project) ⇒ Boolean

Returns:

  • (Boolean)

29
30
31
32
33
34
35
36
37
# File 'app/models/lfs_object.rb', line 29

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