Open
Conversation
KnpPaginatorのCOUNT(DISTINCT)処理による性能問題を解決するため、 カスタムカウントクエリを実装しました。 ## 問題 - 受注/商品/会員管理の一覧画面で、データ量増加に伴い表示が遅延 - 原因: KnpPaginatorが自動実行するCOUNT(DISTINCT o.id) - JOINによる行の膨張(例: 1万注文×3商品=3万行) - DISTINCT処理で3万行→1万件に戻すコストが膨大 ## 解決策 COUNT用クエリとデータ取得用クエリを分離: - COUNT: JOINなしの高速クエリ(インデックス使用) - データ取得: 従来通りJOINあり(必要な50件だけ処理) - knp_paginator.countヒントでカスタムカウントを渡す ## 変更内容 - OrderRepository: countBySearchDataForAdmin()追加 - ProductRepository: countBySearchDataForAdmin()追加 - CustomerRepository: countBySearchData()追加 - 各Controller: JOIN不要な検索時にカスタムカウント使用 ## 期待効果 - COUNT処理時間: 5-10秒 → 0.1秒未満 - 初期表示時間: 数秒 → 1秒未満 - データベース負荷: JOIN処理を完全に排除 Fixes EC-CUBE#6527 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.3 #6571 +/- ##
============================================
- Coverage 78.83% 78.01% -0.83%
- Complexity 6632 6784 +152
============================================
Files 475 475
Lines 26540 26911 +371
============================================
+ Hits 20923 20994 +71
- Misses 5617 5917 +300
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
概要
管理画面の受注/商品/会員一覧ページにおいて、データ量増加に伴う表示遅延を解決します。
Fixes #6527
問題
KnpPaginatorが自動実行する
COUNT(DISTINCT)処理による性能問題:COUNT(DISTINCT o.id)で3万行→1万件に戻すDISTINCT処理解決策
COUNT用クエリとデータ取得用クエリを分離することで、根本的にパフォーマンスを改善:
従来の実装
改善後の実装
変更内容
1. Repository層
3つのRepositoryにカスタムカウントメソッドを追加:
OrderRepository::countBySearchDataForAdmin()ProductRepository::countBySearchDataForAdmin()CustomerRepository::countBySearchData()これらのメソッドは:
2. Controller層
3つのControllerでカスタムカウントを使用:
条件分岐の理由
一部の検索条件(商品名検索など)はJOINが不可避なため、その場合は従来のCOUNT処理を使用。基本的な検索条件のみの場合にカスタムカウントで高速化します。
期待される効果
定量的効果
対象ケース
テスト結果
実行したテスト
セキュリティチェック
チェックリスト