このコミットが含まれているのは:
@@ -6,6 +6,7 @@ class CountsVersionRepr
|
||||
|
||||
def initialize(rows, resource:, language_code:, at:, inclusive:)
|
||||
@rows = rows
|
||||
HistoryAccess.require_many!(rows)
|
||||
@at = at
|
||||
@inclusive = inclusive
|
||||
@resource = resource
|
||||
@@ -15,6 +16,7 @@ class CountsVersionRepr
|
||||
@scripts = master_names(Script)
|
||||
@tag_versions = {}
|
||||
load_tag_versions if resource == 'posts'
|
||||
load_parent_versions if resource == 'tags'
|
||||
end
|
||||
|
||||
def serialise
|
||||
@@ -47,7 +49,7 @@ class CountsVersionRepr
|
||||
.uniq
|
||||
pairs.each_slice(500) do |batch|
|
||||
placeholders = batch.map { '(?, ?)' }.join(', ')
|
||||
scope = TagVersion.all
|
||||
scope = HistoryAccess.visible(TagVersion.all)
|
||||
if @at
|
||||
scope = scope.where("created_at #{ @inclusive ? '<=' : '<' } ?", @at)
|
||||
end
|
||||
@@ -86,6 +88,31 @@ class CountsVersionRepr
|
||||
original_created_before: row.original_created_before&.iso8601 }
|
||||
end
|
||||
|
||||
def parent_point(row) = @at || row.created_at
|
||||
|
||||
def load_parent_versions
|
||||
@parent_versions = {}
|
||||
requests = @rows.flat_map do |row|
|
||||
row.parent_tag_ids.to_s.split.map { [_1.to_i, parent_point(row)] }
|
||||
end.uniq
|
||||
requests.each_slice(100) do |batch|
|
||||
queries = batch.map do |id, point|
|
||||
scope = HistoryAccess.visible(TagVersion.where(tag_id: id))
|
||||
.where('created_at <= ?', point)
|
||||
.where('NOT EXISTS (SELECT 1 FROM tag_versions newer ' +
|
||||
'WHERE newer.tag_id = tag_versions.tag_id AND newer.created_at <= ? ' +
|
||||
'AND newer.version_no > tag_versions.version_no)', point)
|
||||
quoted = TagVersion.connection.quote(point.iso8601(6))
|
||||
scope.select("tag_id, name, names, #{ quoted } AS reference_point").to_sql
|
||||
end
|
||||
next if queries.empty?
|
||||
|
||||
TagVersion.connection.select_all(queries.map { "(#{ _1 })" }.join(' UNION ALL ')).each do |value|
|
||||
@parent_versions[[value['tag_id'], value['reference_point']]] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tag(row)
|
||||
recorded_names = names(row.names)
|
||||
selected = recorded_names.find { _1[:language_code] == @language }
|
||||
@@ -97,7 +124,12 @@ class CountsVersionRepr
|
||||
end
|
||||
{ name: selected&.fetch(:name) || row.name, names: recorded_names,
|
||||
category: row.category, aliases:,
|
||||
parents: row.parent_tag_ids.to_s.split.map { { id: _1.to_i } },
|
||||
parents: row.parent_tag_ids.to_s.split.map do |id|
|
||||
value = @parent_versions[[id.to_i, parent_point(row).iso8601(6)]]
|
||||
snapshots = value && json(value['names'])
|
||||
name = snapshots&.dig(@language, 'name') || value&.fetch('name')
|
||||
{ id: id.to_i, name: }
|
||||
end,
|
||||
deprecated: row.deprecated_at&.iso8601 }
|
||||
end
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする