Class: LfsObject

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

Class Method Summary collapse

Instance Method Summary collapse

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

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, with_fast_statement_timeout, without_order

Class Method Details

.calculate_oid(path) ⇒ Object

rubocop: enable Cop/DestroyAll


48
49
50
# File 'app/models/lfs_object.rb', line 48

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

.destroy_unreferencedObject

rubocop: disable Cop/DestroyAll


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

def self.destroy_unreferenced
  joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id")
      .where(lfs_objects_projects: { id: nil })
      .destroy_all
end

.not_linked_to_project(project) ⇒ Object


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

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

Instance Method Details

#local_store?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/models/lfs_object.rb', line 36

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

#project_allowed_access?(project) ⇒ Boolean

Returns:

  • (Boolean)

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

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