Class: LfsObject
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LfsObject
- Includes:
- AfterCommitQueue, Checksummable, EachBatch, FileStoreMounter, ObjectStorable
- Defined in:
- app/models/lfs_object.rb
Constant Summary collapse
- STORE_COLUMN =
:file_store- BATCH_SIZE =
3000
Constants included from FileStoreMounter
FileStoreMounter::ALLOWED_FILE_FIELDS
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
- .calculate_oid(path) ⇒ Object
- .for_oid_and_size(oid, size) ⇒ Object
- .not_linked_to_project(project, repository_type: nil) ⇒ Object
- .unreferenced_in_batches ⇒ Object
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, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.calculate_oid(path) ⇒ Object
61 62 63 |
# File 'app/models/lfs_object.rb', line 61 def self.calculate_oid(path) self.sha256_hexdigest(path) end |
.for_oid_and_size(oid, size) ⇒ Object
23 24 25 |
# File 'app/models/lfs_object.rb', line 23 def self.for_oid_and_size(oid, size) find_by(oid: oid, size: size) end |
.not_linked_to_project(project, repository_type: nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/models/lfs_object.rb', line 27 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_batches ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/lfs_object.rb', line 50 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
46 47 48 |
# File 'app/models/lfs_object.rb', line 46 def local_store? file_store == LfsObjectUploader::Store::LOCAL end |
#project_allowed_access?(project) ⇒ Boolean
36 37 38 39 40 41 42 43 44 |
# File 'app/models/lfs_object.rb', line 36 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 |