A platform for community discussion. Free, open, simple.
DEV: `SetStore` backed implementation of `requires_set` (#33626)
Selase Krakani57a04e7ec865
diff --git a/migrations/lib/importer/discourse_db.rb b/migrations/lib/importer/discourse_db.rbindex 3643d676a0f..8b56d39716e 100644--- a/migrations/lib/importer/discourse_db.rb+++ b/migrations/lib/importer/discourse_db.rb@@ -2,6 +2,8 @@module Migrations::Importerclass DiscourseDB+ QueryResult = Data.define(:rows, :column_count)+COPY_BATCH_SIZE = 1_000SKIP_ROW_MARKER = :"$skip"@@ -93,15 +95,31 @@ module Migrations::Importerenddef query_array(sql, *params)+ query_result(sql, *params).rows+ end++ def query_result(sql, *params)@connection.send_query_params(sql, params)@connection.set_single_row_mode- Enumerator.new do |y|- while (result = @connection.get_result)- result.stream_each_row { |row| y.yield(row) }- result.clear+ first_result = @connection.get_result+ return QueryResult.new(rows: Enumerator.new {}, column_count: 0) unless first_result++ column_count = first_result.nfields+ single_column = column_count == 1++ rows_enumerator =+ Enumerator.new do |y|+ first_result.stream_each_row { |row| single_column ? y << row[0] : y << row }+ first_result.clear++ while (result = @connection.get_result)+ result.stream_each_row { |row| single_column ? y << row[0] : y << row }+ result.clear+ endend- end++ QueryResult.new(rows: rows_enumerator, column_count:)enddef closediff --git a/migrations/lib/importer/shared_data.rb b/migrations/lib/importer/shared_data.rbindex 7896bdedbb2..d426135ea43 100644--- a/migrations/lib/importer/shared_data.rb+++ b/migrations/lib/importer/shared_data.rb@@ -7,7 +7,13 @@ module Migrations::Importerenddef load_set(sql)- @discourse_db.query_array(sql).map(&:first).to_set+ result = @discourse_db.query_result(sql)+ depth = result.column_count - 1++ set = Migrations::SetStore.create(depth)+ set.bulk_add(result.rows)++ setenddef load_mapping(sql)