プロジェクト

全般

プロフィール

Vote #74480

完了

Project authorization EnabledModule N+1 queries

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Code cleanup/refactoring_30
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
30
version_id:
70
issue_org_id:
15058
author_id:
87200
assigned_to_id:
0
comments:
3
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

There's a problem with project authorization that causes N+1 queries (one per project in @projects).

In ApplicationController#authorize redmine checks authorization on @project or @projects. This triggers the code in Project#allowed_permissions which calls @enabled_modules.pluck(:name)@.

The problem here is that pluck circumvents preloading, so no matter wether we do @@projects = Project.includes(:enabled_modules).where(conditions)@ in a controller, it will still trigger one extra query per project.

Given that the EnableModule model is tiny, this could be prevented by using @enabled_modules.map(&:name)@ instead.


journals

Fixed in r12228, @#pluck@ won't be called is the association is preloaded.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Nice solution, I didn't know about @loaded?@ until now.
--------------------------------------------------------------------------------

Admin Redmine さんが3年以上前に更新

  • カテゴリCode cleanup/refactoring_30 にセット
  • 対象バージョン2.4.0_70 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0