Class: Gitlab::BackgroundMigration::LinkLfsObjectsProjects

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/link_lfs_objects_projects.rb

Overview

Create missing LfsObjectsProject records for forks

Defined Under Namespace

Classes: ForkNetworkMember, LfsObjectsProject

Constant Summary collapse

BATCH_SIZE =
1000

Instance Method Summary collapse

Instance Method Details

#perform(start_id, end_id) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gitlab/background_migration/link_lfs_objects_projects.rb', line 47

def perform(start_id, end_id)
  lfs_objects_projects =
    Gitlab::BackgroundMigration::LinkLfsObjectsProjects::LfsObjectsProject
      .linkable
      .where(id: start_id..end_id)

  return if lfs_objects_projects.empty?

  lfs_objects_projects.find_each do |lop|
    ForkNetworkMember
      .select("#{lop.lfs_object_id}, fork_network_members.project_id, NOW(), NOW()")
      .without_lfs_object(lop.lfs_object_id)
      .where(forked_from_project_id: lop.project_id)
      .each_batch(of: BATCH_SIZE) do |batch, index|
        execute <<~SQL
          INSERT INTO lfs_objects_projects (lfs_object_id, project_id, created_at, updated_at)
          #{batch.to_sql}
        SQL

        logger.info(message: "LinkLfsObjectsProjects: created missing LfsObjectsProject records for LfsObject #{lop.lfs_object_id}")
      end
  end
end