This commit is contained in:
2026-02-10 00:12:22 +09:00
parent 9b7fc9059d
commit 70e5393702
3 changed files with 26 additions and 7 deletions
@@ -6,7 +6,9 @@ class NicoTagsController < ApplicationController
cursor = params[:cursor].presence
q = Tag.nico_tags
.includes(:tag_name, linked_tags: :tag_name)
.joins(:tag_name)
.left_joins(tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page, linked_tags: :tag_name)
.order(updated_at: :desc)
q = q.where('tags.updated_at < ?', Time.iso8601(cursor)) if cursor
+18 -5
View File
@@ -4,10 +4,15 @@ class TagsController < ApplicationController
tags =
if post_id.present?
Tag.joins(:posts).where(posts: { id: post_id })
Tag.joins(:posts, :tag_name)
else
Tag.all
Tag.joins(:tag_name)
end
.left_joins(tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page)
if post_id.present?
tags = tags.where(posts: { id: post_id })
end
render json: tags.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki])
end
@@ -33,7 +38,9 @@ class TagsController < ApplicationController
matched_alias_by_tag_name_id[canonical_id] ||= alias_name
end
base = Tag.joins(:tag_name).includes(:tag_name)
base = Tag.joins(:tag_name)
.left_joins(tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page)
base = base.where('tags.post_count > 0') if present_only
canonical_hit =
@@ -58,7 +65,10 @@ class TagsController < ApplicationController
end
def show
tag = Tag.find_by(id: params[:id])
tag = Tag.joins(:tag_name)
.left_joins(tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page)
.find_by(id: params[:id])
if tag
render json: tag.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki])
else
@@ -70,7 +80,10 @@ class TagsController < ApplicationController
name = params[:name].to_s.strip
return head :bad_request if name.blank?
tag = Tag.joins(:tag_name).includes(:tag_name).find_by(tag_names: { name: })
tag = Tag.joins(:tag_name)
.left_joins(tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page)
.find_by(tag_names: { name: })
if tag
render json: tag.as_json(only: [:id, :category, :post_count], methods: [:name, :has_wiki])
else
@@ -3,7 +3,11 @@ class WikiPagesController < ApplicationController
def index
title = params[:title].to_s.strip
return render json: WikiPage.all.as_json(methods: [:title]) if title.blank?
if title.blank?
return render json: WikiPage.joins(:tag_name)
.includes(:tag_name)
.as_json(methods: [:title])
end
q = WikiPage.joins(:tag_name).includes(:tag_name)
.where('tag_names.name LIKE ?', "%#{ WikiPage.sanitize_sql_like(title) }%")