1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class AddFileInfoToCollection < ActiveRecord::Migration
11 pdhs_str << "'" << pdh << "'" << ","
14 collections = ActiveRecord::Base.connection.exec_query(
15 "SELECT DISTINCT portable_data_hash, manifest_text FROM collections "\
16 "WHERE portable_data_hash IN (#{pdhs_str[0..-2]}) "
19 collections.rows.each do |row|
20 manifest = Keep::Manifest.new(row[1])
21 ActiveRecord::Base.connection.exec_query("BEGIN")
22 ActiveRecord::Base.connection.exec_query("UPDATE collections SET file_count=#{manifest.files_count}, "\
23 "file_size_total=#{manifest.files_size} "\
24 "WHERE portable_data_hash='#{row[0]}'")
25 ActiveRecord::Base.connection.exec_query("COMMIT")
30 add_column :collections, :file_count, :integer, default: 0, null: false
31 add_column :collections, :file_size_total, :integer, default: 0, null: false
33 distinct_pdh_count = ActiveRecord::Base.connection.exec_query(
34 "SELECT DISTINCT portable_data_hash FROM collections"
37 # Generator that queries for all the distince pdhs greater than last_pdh
38 ordered_pdh_query = lambda { |last_pdh, &block|
39 pdhs = ActiveRecord::Base.connection.exec_query(
40 "SELECT DISTINCT portable_data_hash FROM collections "\
41 "WHERE portable_data_hash > '#{last_pdh}' "\
42 "ORDER BY portable_data_hash LIMIT 1000"
44 pdhs.rows.each do |row|
49 batch_size_max = 1 << 28 # 256 MiB
50 Container.group_pdhs_for_multiple_transactions(ordered_pdh_query,
53 "AddFileInfoToCollection") do |pdhs|
59 remove_column :collections, :file_count
60 remove_column :collections, :file_size_total