クエリ・パフォーマンスの改善(#258) (#259)

#258

#258

#258

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #259
This commit was merged in pull request #259.
This commit is contained in:
2026-02-11 13:26:10 +09:00
parent 9b7fc9059d
commit 1a776e348a
6 changed files with 64 additions and 36 deletions
@@ -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) }%")
@@ -11,7 +15,9 @@ class WikiPagesController < ApplicationController
end
def show
page = WikiPage.find_by(id: params[:id])
page = WikiPage.joins(:tag_name)
.includes(:tag_name)
.find_by(id: params[:id])
render_wiki_page_or_404 page
end
@@ -19,7 +25,7 @@ class WikiPagesController < ApplicationController
title = params[:title].to_s.strip
page = WikiPage.joins(:tag_name)
.includes(:tag_name)
.find_by(tag_names: { name: title })
.find_by(tag_name: { name: title })
render_wiki_page_or_404 page
end
@@ -47,7 +53,7 @@ class WikiPagesController < ApplicationController
from = params[:from].presence
to = params[:to].presence
page = WikiPage.find(id)
page = WikiPage.joins(:tag_name).includes(:tag_name).find(id)
from_rev = from && page.wiki_revisions.find(from)
to_rev = to ? page.wiki_revisions.find(to) : page.current_revision
@@ -131,7 +137,9 @@ class WikiPagesController < ApplicationController
def changes
id = params[:id].presence
q = WikiRevision.includes(:wiki_page, :created_user).order(id: :desc)
q = WikiRevision.joins(wiki_page: :tag_name)
.includes(:created_user, wiki_page: :tag_name)
.order(id: :desc)
q = q.where(wiki_page_id: id) if id
render json: q.limit(200).map { |rev|
@@ -139,7 +147,7 @@ class WikiPagesController < ApplicationController
pred: rev.base_revision_id,
succ: nil,
wiki_page: { id: rev.wiki_page_id, title: rev.wiki_page.title },
user: { id: rev.created_user.id, name: rev.created_user.name },
user: rev.created_user && { id: rev.created_user.id, name: rev.created_user.name },
kind: rev.kind,
message: rev.message,
timestamp: rev.created_at }