Repository navigation
[サイト内検索] ページ数が多い場合の検索パフォーマンスを向上しました - #2223
Merged
Merged
Conversation
## 概要 サイト内検索プラグインにおけるPageRole::getPageRoles()メソッドの パフォーマンス問題を解決するため、データベースINDEXを追加しました。 ## 変更内容 - page_rolesテーブルに複合INDEX(page_id, group_id)を追加 - group_usersテーブルに複合INDEX(user_id, group_id)を追加 - パフォーマンステストを実装して効果を検証 ## パフォーマンス改善結果 1,000ユーザーでの検証結果: - 全体実行時間: 617ms → 324ms(47.5%改善) - PageRoleクエリ時間: 160ms → 80ms(49.7%改善) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- テストメソッド名をcamelCaseに変更 - function キーワード後のスペースを追加(phpcbf自動修正) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
サイト内検索プラグインにおいて、PageRole::getPageRoles()が全ページ数だけ実行されていました。
処理時間を計測したところ、getPageRoles()1回の実行時間は約140msでした。
よって、ページ数が多いほど深刻なパフォーマンス問題が発生します。
上記事象を解決するため、まずはINDEXを追加しました。
変更内容
マイグレーション
page_rolesテーブルに複合INDEXidx_page_roles_on_page_id_and_group_id (page_id, group_id)を追加group_usersテーブルに複合INDEXidx_group_users_on_user_id_and_group_id (user_id, group_id)を追加技術的詳細
問題の原因
PageRole::getPageRoles()でのJOINクエリにINDEXが不足page_rolesとgroup_usersテーブル間のJOIN操作が遅い解決方法
(page_id, group_id)と(user_id, group_id)に複合INDEXを追加影響範囲
対応しなかったこと