Skip to content

ブログの記事数やカテゴリ数が多い場合に、カテゴリ一覧ウィジェットを使用するとメモリオーバーエラーになる#4420

Open
seto1 wants to merge 3 commits into
baserproject:5.2.xfrom
seto1:getCategoryPostCounts
Open

ブログの記事数やカテゴリ数が多い場合に、カテゴリ一覧ウィジェットを使用するとメモリオーバーエラーになる#4420
seto1 wants to merge 3 commits into
baserproject:5.2.xfrom
seto1:getCategoryPostCounts

Conversation

@seto1

@seto1 seto1 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

メモリの問題は、BlogCategoriesTableの以下の行を削除することで解決しました。

->contain(['BlogPosts' => ['BlogContents' => ['Contents']]])

ただ、それだけだとデータ量が多い場合に数十秒ほど処理時間がかかってしまうため、さらに以下の調整を行っています。

  • カテゴリ毎に記事数をカウントしている箇所の削除
  • 代わりに1回のクエリでカテゴリ毎の記事数を取得するように変更

確認の際に使用したデータ量は以下です。

  • カテゴリ数: 109
  • 記事数: 300,009

ご確認お願いします。

Copilot AI review requested due to automatic review settings June 11, 2026 01:53
@github-actions github-actions Bot requested a review from kaburk June 11, 2026 01:53
@github-actions github-actions Bot requested review from katokaisya and ryuring June 11, 2026 01:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

カテゴリ数・記事数が多い環境で「カテゴリ一覧ウィジェット」がメモリオーバーや極端な遅延を起こす問題に対応するため、カテゴリ取得時の関連データ読み込みを削減し、カテゴリ別記事数の取得方法を集計クエリ中心に見直すPRです。

Changes:

  • BlogCategoriesTable::_getCategoryList()contain(['BlogPosts' => ...]) を削除し、カテゴリ一覧取得時のメモリ消費を抑制
  • カテゴリ別記事数をカテゴリごとに都度 count する方式から、1回の集計クエリ+アプリ側での合算に変更
  • 記事数集計用の getCategoryPostCounts() を追加し、再帰呼び出し間で集計結果を使い回すように変更

Comment thread plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php
Comment thread plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php Outdated
Comment thread plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php Outdated
Comment thread plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php
seto1 and others added 2 commits June 11, 2026 11:59
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ryuring

ryuring commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

テストが失敗してるみたいですので、確認お願いします @seto1

@kaburk

kaburk commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@seto1 おそらく

], $options); 

のところが消えちゃっているので、戻してあげてください。
スクリーンショット 2026-06-12 12 16 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants