このコミットが含まれているのは:
2026-10-31 14:25:31 +09:00
コミット 5b77285a6b
10個のファイルの変更、78行の追加、54行の削除
+21 -8
ファイルの表示
@@ -72,14 +72,27 @@ class CountsAxes
end
end
def count_expression
return 'COUNT(DISTINCT v.id)' unless rows.any? { _1['field'] == 'tags' }
# Keep tag occurrences even when several private tags share one masked label.
values = ['v.id', "COALESCE(CONCAT('internal:', tag_entry.tag_id), " +
"CONCAT('external:', tag_entry.external_tag_id))"]
values << 'changed.field_key' if rows.any? { _1['field'] == 'changed_field' }
"COUNT(DISTINCT #{ values.join(', ') })"
def grouped_sql(scope, indexes = all.each_index.to_a)
keys = indexes.map { "a#{ _1 }" }
selected = indexes.map { "#{ expressions[_1] } AS a#{ _1 }" }
identities = ['v.id']
if rows.any? { _1['field'] == 'tags' }
# Raw identities stay inside COUNT; masked tag occurrences remain additive.
identities << "COALESCE(CONCAT('internal:', tag_entry.tag_id), " +
"CONCAT('external:', tag_entry.external_tag_id))"
identities << 'changed.field_key' if rows.any? { _1['field'] == 'changed_field' }
end
members = identities.each_index.map { "counts_member_#{ _1 }" }
selected += identities.each_with_index.map { |expression, index|
"#{ expression } AS #{ members[index] }"
}
# Evaluate correlated visibility subqueries before grouping. LIMIT prevents
# derived-table merging, so ONLY_FULL_GROUP_BY sees ordinary projected columns.
projection = scope.except(:select, :order).select(Arel.sql(selected.join(', ')))
.limit(18_446_744_073_709_551_615).to_sql
fields = keys + ["COUNT(DISTINCT #{ members.join(', ') }) AS count"]
grouping = keys.empty? ? '' : " GROUP BY #{ keys.join(', ') }"
"SELECT #{ fields.join(', ') } FROM (#{ projection }) counts_values#{ grouping }"
end
def joins(fields = all.map { _1['field'] })