Project

General

Profile

Actions

Defect #15058

closed

Project authorization EnabledModule N+1 queries

Added by Felix Bünemann about 11 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Code cleanup/refactoring
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

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

In ApplicationController#authorize redmine checks authorization on Herve Harster or Projects 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.

Actions

Also available in: Atom PDF