このコミットが含まれているのは:
2026-09-27 15:07:24 +09:00
コミット c912bebbee
40個のファイルの変更、473行の追加、377行の削除
+10 -6
ファイルの表示
@@ -7,6 +7,8 @@ class PostsController < ApplicationController
end
def index
locale = resolve_locale!
url = params[:url].presence
title = params[:title].presence
original_created_from = params[:original_created_from].presence
@@ -46,7 +48,7 @@ class PostsController < ApplicationController
'COALESCE(pt_max.max_updated_at, posts.updated_at))'
q =
filtered_posts
filtered_posts(locale)
.joins("LEFT JOIN (#{ pt_max_sql }) pt_max ON pt_max.post_id = posts.id")
.reselect('posts.*', Arel.sql("#{ updated_at_all_sql } AS updated_at_all"))
.preload(:external_tags, :uploaded_user, :parents, :children,
@@ -102,8 +104,10 @@ class PostsController < ApplicationController
end
def random
locale = resolve_locale!
post =
filtered_posts
filtered_posts(locale)
.preload(:uploaded_user, :parents, :children,
post_tags: [:sections, { tag: [:deerjikists, :materials,
{ tag_name: :wiki_page }] }])
@@ -394,19 +398,19 @@ class PostsController < ApplicationController
private
def filtered_posts
def filtered_posts locale
tag_names = params[:tags].to_s.split
match_type = params[:match]
if tag_names.present?
filter_posts_by_tags(tag_names, match_type)
filter_posts_by_tags(locale, tag_names, match_type)
else
Post.all
end
end
def filter_posts_by_tags tag_names, match_type
def filter_posts_by_tags locale, tag_names, match_type
literals = tag_names.map do |raw_name|
{ name: TagName.canonicalise(raw_name.sub(/\Anot:/i, '')).first,
{ name: TagName.canonicalise(locale, raw_name.sub(/\Anot:/i, '')).first,
negative: raw_name.downcase.start_with?('not:') }
end
+16 -14
ファイルの表示
@@ -430,7 +430,7 @@ class TagsController < ApplicationController
else
tag.update!(category:, deprecated_at: deprecated ? Time.current : nil)
end
rename_tag_name!(tag, name) if name_changed
rename_tag_name!(locale, tag, name) if name_changed
alias_names << old_name if name_changed
alias_names.delete(name)
@@ -701,13 +701,13 @@ class TagsController < ApplicationController
false
end
def rename_tag_name! tag, name
return if name == tag.name
def rename_tag_name! locale, tag, name
return if name == tag.name(locale.language_code)
current_tag_name = tag.tag_name
target_tag_name = TagName.find_by(name:)
current_tag_name = tag.tag_name(locale.language_code)
target_tag_name = TagName.find_by(language_code: locale.language_code, name:)
if target_tag_name.nil?
unless target_tag_name
current_tag_name.update!(name:)
return
end
@@ -722,19 +722,21 @@ class TagsController < ApplicationController
TagVersioning.ensure_snapshot!(old_owner_tag, created_by_user: current_user)
end
promoted_tag_name.update!(canonical: nil)
promoted_tag_name.update!(canonical_id: nil, primary_flg: true)
TagName.where(canonical_id: current_tag_name.id)
TagName.where(tag:,
language_code: current_tag_name.language.language_code,
primary_flg: false)
.where.not(id: promoted_tag_name.id)
.find_each do |alias_tag_name|
alias_tag_name.update!(canonical: promoted_tag_name)
alias_tag_name.update!(canonical_id: promoted_tag_name, primary_flg: false)
end
current_tag_name.wiki_page&.update!(tag_name: promoted_tag_name)
tag.update!(tag_name: promoted_tag_name)
current_tag_name.wiki_page&.update!(tag_name_id: promoted_tag_name.id)
tag.update!(tag_name_id: promoted_tag_name.id)
current_tag_name.association(:wiki_page).reset
current_tag_name.association(:tag).reset
current_tag_name.reload.update!(canonical: promoted_tag_name)
current_tag_name.reload.update!(canonical_id: promoted_tag_name, primary_flg: false)
return unless old_owner_tag && old_owner_tag != tag
@@ -766,12 +768,12 @@ class TagsController < ApplicationController
current_aliases.each do |alias_tag_name|
next if alias_names.include?(alias_tag_name.name)
alias_tag_name.update!(canonical: nil)
alias_tag_name.update!(canonical_id: nil)
end
alias_names.each do |alias_name|
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
alias_tag_name.update!(canonical: tag.tag_name)
alias_tag_name.update!(canonical_id: tag.tag_name.id)
end
affected_tags.compact.uniq.each do |affected_tag|
+3 -6
ファイルの表示
@@ -51,12 +51,10 @@ class Tag < ApplicationRecord
has_many :tag_versions
has_many :tag_names
belongs_to :tag_name
delegate :wiki_page, to: :tag_name
attribute :version_no, :integer, default: 1
delegate :name, to: :tag_name, allow_nil: true
validates :tag_name, presence: true
enum :category, deerjikist: 'deerjikist',
@@ -84,9 +82,8 @@ class Tag < ApplicationRecord
'mtr:' => :material,
'meta:' => :meta }.freeze
def name= val
(self.tag_name ||= build_tag_name).name = val
end
def tag_name(language_code) = tag_names.find_by(language_code:, primary_flg: true)
def name(language_code) = tag_name(language_code)&.name
def deprecated? = deprecated_at?
@@ -276,7 +273,7 @@ class Tag < ApplicationRecord
end
TagVersioning.record!(source_tag, event_type: :discard, created_by_user:)
source_tag.tag_names.update_all(tag_id: source_tag.id, primary_key: false,
source_tag.tag_names.update_all(tag_id: target_tag.id, primary_flg: false,
updated_at: Time.current)
source_tag.destroy!
+3 -3
ファイルの表示
@@ -13,8 +13,8 @@ class TagName < ApplicationRecord
def primary? = primary_flg
def canonical = TagName.find_by(language:, tag:, primary_flg: true)
def aliases = TagName.where(language:, tag:, primary_flg: false)
def canonical = TagName.find_by(language_code:, tag_id:, primary_flg: true)
def aliases = TagName.where(language_code:, tag_id:, primary_flg: false)
def self.canonicalise locale, names
names = Array(names).map { |n| n.to_s.strip }.reject(&:blank?)
@@ -23,7 +23,7 @@ class TagName < ApplicationRecord
tns = TagName.where(language_code: locale.language_code, name: names).index_by(&:name)
names.map { |name|
if tns[name].primary_flg
if !(tns[name]) || tns[name].primary?
name
else
TagName.find_by(language_code: locale.language_code,
+7 -8
ファイルの表示
@@ -10,7 +10,7 @@ class PostCreatePlan
def build! locale
direct_tag_specs, tag_sections = parse_direct_tag_specs(locale)
default_tag_specs = build_default_tag_specs(direct_tag_specs)
default_tag_specs = build_default_tag_specs(locale, direct_tag_specs)
snapshot_tag_specs = merge_tag_specs(direct_tag_specs + default_tag_specs)
preload_existing_tags_by_name!(snapshot_tag_specs.map { _1[:name] })
validate_new_tag_specs!(snapshot_tag_specs)
@@ -263,12 +263,11 @@ class PostCreatePlan
end
def resolved_tag_name locale, name
tag_name = TagName.find_by!(language_code: locale.language_code, name:)
unless tag_name.primary_flg
tag_name = TagName.find_by!(language_code: locale.language_code,
tag_id: tag_name.tag_id,
primary_flg: true)
end
tag_name.name
tag_name = TagName.find_by(language_code: locale.language_code, name:)
return name if !(tag_name) || tag_name.primary?
TagName.find_by!(language_code: locale.language_code,
tag_id: tag_name.tag_id,
primary_flg: true).name
end
end
+3 -3
ファイルの表示
@@ -74,13 +74,13 @@ class PostCreator
normalised_parent_post_ids: @attributes[:normalised_parent_post_ids] || [],
video_ms: @attributes[:video_ms] }
else
build_materialised_plan
build_materialised_plan(locale)
end
end
end
def build_materialised_plan
plan = PostCreatePlan.new(attributes: @attributes).build!
def build_materialised_plan locale
plan = PostCreatePlan.new(attributes: @attributes).build!(locale)
snapshot_tags = materialise_tags(plan[:snapshot_tag_specs] || [])
post_tags = materialise_tags(plan[:post_tag_specs] || [])
{