diff --git a/backend/app/controllers/nico_tags_controller.rb b/backend/app/controllers/nico_tags_controller.rb index da3d831..b6acaf2 100644 --- a/backend/app/controllers/nico_tags_controller.rb +++ b/backend/app/controllers/nico_tags_controller.rb @@ -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 diff --git a/backend/app/controllers/tags_controller.rb b/backend/app/controllers/tags_controller.rb index 1c5dcb2..a504f10 100644 --- a/backend/app/controllers/tags_controller.rb +++ b/backend/app/controllers/tags_controller.rb @@ -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 diff --git a/backend/app/controllers/wiki_pages_controller.rb b/backend/app/controllers/wiki_pages_controller.rb index 20b2912..e9960ed 100644 --- a/backend/app/controllers/wiki_pages_controller.rb +++ b/backend/app/controllers/wiki_pages_controller.rb @@ -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) }%")