このコミットが含まれているのは:
@@ -37,7 +37,7 @@ class NicoTagsController < ApplicationController
|
||||
if link_status.in?(['linked', 'unlinked'])
|
||||
exists_sql =
|
||||
'EXISTS (SELECT 1 FROM nico_tag_relations ' \
|
||||
'WHERE nico_tag_relations.nico_tag_id = tags.id)'
|
||||
'WHERE nico_tag_relations.nico_tag_id = external_tags.id)'
|
||||
q = link_status == 'linked' ? q.where(exists_sql) : q.where("NOT #{ exists_sql }")
|
||||
end
|
||||
|
||||
@@ -45,21 +45,21 @@ class NicoTagsController < ApplicationController
|
||||
sort_sql =
|
||||
case order[0]
|
||||
when 'name'
|
||||
'tag_names.name'
|
||||
'external_tags.name'
|
||||
when 'updated_at'
|
||||
'post_tag_max.max_created_at'
|
||||
else
|
||||
"tags.#{ order[0] }"
|
||||
"external_tags.#{ order[0] }"
|
||||
end
|
||||
tags = q.reselect('tags.*',
|
||||
tags = q.reselect('external_tags.*',
|
||||
Arel.sql('post_tag_max.max_created_at AS recent_post_tag_created_at'))
|
||||
.order(Arel.sql("#{ sort_sql } #{ order[1] }, tags.id #{ order[1] }"))
|
||||
.order(Arel.sql("#{ sort_sql } #{ order[1] }, external_tags.id #{ order[1] }"))
|
||||
.limit(limit)
|
||||
.offset((page - 1) * limit)
|
||||
.to_a
|
||||
|
||||
render json: { tags: tags.map { |tag|
|
||||
TagRepr.base(tag).merge(
|
||||
external_tag_json(tag).merge(
|
||||
recent_post_tag_created_at: tag.recent_post_tag_created_at,
|
||||
linked_tags: tag.linked_tags.map { |lt| TagRepr.base(lt) })
|
||||
}, count: }
|
||||
@@ -85,7 +85,9 @@ class NicoTagsController < ApplicationController
|
||||
tag.linked_tags = linked_tags
|
||||
tag.save!
|
||||
|
||||
NicoTagVersionRecorder.record!(tag:, event_type: :update, created_by_user: current_user)
|
||||
NicoTagVersionRecorder.record!(external_tag: tag,
|
||||
event_type: :update,
|
||||
created_by_user: current_user)
|
||||
end
|
||||
|
||||
render json: tag.linked_tags.map { |t| TagRepr.base(t) }, status: :ok
|
||||
@@ -97,6 +99,18 @@ class NicoTagsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def external_tag_json tag
|
||||
{ id: tag.id,
|
||||
name: "#{ tag.platform }:#{ tag.name }",
|
||||
category: 'nico',
|
||||
post_count: tag.post_count,
|
||||
created_at: tag.created_at,
|
||||
updated_at: tag.created_at,
|
||||
deprecated_at: nil,
|
||||
aliases: [],
|
||||
parents: [] }
|
||||
end
|
||||
|
||||
def render_nico_tag_form_record_invalid record
|
||||
if record.is_a?(TagName) || record.is_a?(Tag)
|
||||
render_validation_error fields: { tags: record.errors.full_messages.map { |message|
|
||||
|
||||
@@ -43,50 +43,19 @@ class PostVersionsController < ApplicationController
|
||||
private
|
||||
|
||||
def serialise_versions rows
|
||||
rows = rows.to_a
|
||||
user_ids = rows.map(&:created_by_user_id).compact.uniq
|
||||
users_by_id = User.where(id: user_ids).pluck(:id, :name).to_h
|
||||
snapshots = rows.flat_map { |row|
|
||||
[normalise_json(row.tags_json),
|
||||
normalise_json(row.attributes['prev_tags_json']) || []]
|
||||
}
|
||||
external_tag_names = external_tag_names_for(snapshots)
|
||||
|
||||
rows.map do |row|
|
||||
cur_tags =
|
||||
normalise_json(row.tags_json)
|
||||
.sort_by { [(case _1.fetch('category')
|
||||
when 'deerjikist'
|
||||
0
|
||||
when 'meme'
|
||||
1
|
||||
when 'character'
|
||||
2
|
||||
when 'general'
|
||||
3
|
||||
when 'material'
|
||||
4
|
||||
when 'meta'
|
||||
5
|
||||
else
|
||||
6
|
||||
end),
|
||||
_1.fetch('name').downcase] }
|
||||
.map { Post.tag_snapshot_literal(_1) }
|
||||
prev_tags =
|
||||
(normalise_json(row.attributes['prev_tags_json']) || [])
|
||||
.sort_by { [(case _1.fetch('category')
|
||||
when 'deerjikist'
|
||||
0
|
||||
when 'meme'
|
||||
1
|
||||
when 'character'
|
||||
2
|
||||
when 'general'
|
||||
3
|
||||
when 'material'
|
||||
4
|
||||
when 'meta'
|
||||
5
|
||||
else
|
||||
6
|
||||
end),
|
||||
_1.fetch('name').downcase] }
|
||||
.map { Post.tag_snapshot_literal(_1) }
|
||||
cur_tags = snapshot_tag_literals(normalise_json(row.tags_json), external_tag_names)
|
||||
prev_tags = snapshot_tag_literals(
|
||||
normalise_json(row.attributes['prev_tags_json']) || [], external_tag_names)
|
||||
|
||||
{ post_id: row.post_id,
|
||||
version_no: row.version_no,
|
||||
@@ -113,6 +82,40 @@ class PostVersionsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def external_tag_names_for snapshots
|
||||
ids = snapshots.flatten.filter_map { _1['external_tag_id'] }.uniq
|
||||
names = ExternalTag.where(id: ids).pluck(:id, :platform, :name).to_h { |id, platform, name|
|
||||
[id, "#{ platform }:#{ name }"]
|
||||
}
|
||||
missing_ids = ids - names.keys
|
||||
|
||||
NicoTagVersion
|
||||
.where(tag_id: missing_ids)
|
||||
.order(:tag_id, version_no: :desc)
|
||||
.pluck(:tag_id, :name)
|
||||
.each { |id, name| names[id] ||= name }
|
||||
|
||||
names
|
||||
end
|
||||
|
||||
def snapshot_tag_literals snapshots, external_tag_names
|
||||
snapshots
|
||||
.filter_map { |snapshot|
|
||||
if snapshot.key?('tag_id')
|
||||
[tag_category_order(snapshot['category']),
|
||||
Post.tag_snapshot_literal(snapshot)]
|
||||
elsif external_tag_names[snapshot['external_tag_id']]
|
||||
[6, external_tag_names[snapshot['external_tag_id']]]
|
||||
end
|
||||
}
|
||||
.sort_by { |order, name| [order, name.downcase] }
|
||||
.map(&:second)
|
||||
end
|
||||
|
||||
def tag_category_order category
|
||||
['deerjikist', 'meme', 'character', 'general', 'material', 'meta'].index(category) || 6
|
||||
end
|
||||
|
||||
def build_version_tags cur_tags, prev_tags
|
||||
(cur_tags | prev_tags).map do |name|
|
||||
type =
|
||||
|
||||
@@ -653,7 +653,7 @@ class PostsController < ApplicationController
|
||||
|
||||
def editable_tag_names_from_version version
|
||||
version.tags_json
|
||||
.reject { _1.fetch('category') == 'nico' }
|
||||
.select { _1.key?('tag_id') }
|
||||
.map { Post.tag_snapshot_literal(_1) }
|
||||
.sort
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする