このコミットが含まれているのは:
@@ -24,7 +24,7 @@ class CountsTableExport
|
||||
@child_sort = QueryState.list(params.fetch('child_sort', '')).map { _1.split(':', -1) }
|
||||
@child_sort.each do |path, direction, *extra|
|
||||
raise ArgumentError if extra.any? || !['asc', 'desc'].include?(direction)
|
||||
raise ArgumentError unless path&.match?(/\A[a-zA-Z_]+(?:\.[a-zA-Z]+)*\/[a-zA-Z]+\z/)
|
||||
raise ArgumentError unless path&.match?(/\A[a-zA-Z_]+(?:\.[a-zA-Z_]+)*\/[a-zA-Z_]+\z/)
|
||||
end
|
||||
@format = params.fetch('format', 'json')
|
||||
@resource = params.fetch('resource', 'posts')
|
||||
@@ -55,21 +55,26 @@ class CountsTableExport
|
||||
end
|
||||
end
|
||||
|
||||
def body(progress: nil)
|
||||
def body(progress: nil, phase: nil)
|
||||
Enumerator.new do |output|
|
||||
ApplicationRecord.transaction(isolation: :repeatable_read) do
|
||||
@language_names = Language.pluck(:code, :name).to_h
|
||||
processed = 0
|
||||
started = false
|
||||
first = true
|
||||
@query.each_page do |page|
|
||||
@query.each_page(before_page: -> { phase&.call('aggregating') }) do |page|
|
||||
total = @summary ? nil : page[:count]
|
||||
progress&.call(processed, total)
|
||||
phase&.call('writing')
|
||||
unless started
|
||||
metadata = page.except(:versions, :cells, :axis_labels, :column_values,
|
||||
metadata = page.except(:versions, :cells, :axis_labels, :axis_names, :column_values,
|
||||
:row_headers, :column_headers, :pivot_totals).merge(
|
||||
resource:, record_unit: @summary && format == 'json' ? 'pivot_cell' : 'row',
|
||||
body_row_totals: 'once_per_logical_group', page_grand_total_repeated: false,
|
||||
logical_count_unit: 'regular_result_rows',
|
||||
name_collection: 'all_recorded_languages',
|
||||
name_columns: @query.population.definition.name_columns,
|
||||
aggregate_records_in_logical_count: false,
|
||||
filters: @params.select { |key, _value| CountsTableQuery::KEYS.include?(key) ||
|
||||
key == 'measures' || QueryState.valid_key?(key) },
|
||||
fields: @query.population.definition.metadata,
|
||||
@@ -92,7 +97,7 @@ class CountsTableExport
|
||||
labels = pivot_row_labels(header, page)
|
||||
values = labels + records.map { _1[:count] }
|
||||
output << CSV.generate_line(values.map { safe(_1) }, row_sep: "\r\n")
|
||||
processed += records.length
|
||||
processed += 1
|
||||
progress&.call(processed, nil)
|
||||
else
|
||||
records.each do |record|
|
||||
@@ -232,7 +237,15 @@ class CountsTableExport
|
||||
else
|
||||
'data'
|
||||
end
|
||||
values = row[:values].each_with_index.to_h { |value, index| ["a#{ index }", value] }
|
||||
column[:values].each_with_index do |value, index|
|
||||
values["a#{ @query.axes.rows.length + index }"] = value
|
||||
end
|
||||
names = page.fetch(:axis_names, {}).to_h do |key, entries|
|
||||
[key, entries.fetch(values[key].to_s, {})]
|
||||
end
|
||||
{ row: row[:values], column: column[:values], kind:,
|
||||
axis_names: names,
|
||||
row_kind: row[:kind], column_kind: column[:kind],
|
||||
row_depth: row[:values].length, column_depth: column[:values].length,
|
||||
label_key: CountsPivotLayout.label_key(@query.axes.rows.length, @query.axes.columns.length,
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする