Skip to content

Commit abe9709

Browse files
authored
Reduce N+1 queries on school move index (#3232)
By preloading the patient's school, and the school move's school, we avoid needing a query to the database for each school move rendered on this page.
2 parents ac88722 + d3cd1e2 commit abe9709

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/controllers/school_moves_controller.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ class SchoolMovesController < ApplicationController
99
layout "full"
1010

1111
def index
12-
@pagy, @school_moves = pagy(policy_scope(SchoolMove).order(:updated_at))
12+
school_moves =
13+
policy_scope(SchoolMove).includes(
14+
:school,
15+
:organisation,
16+
patient: :school
17+
).order(:updated_at)
18+
19+
@pagy, @school_moves = pagy(school_moves)
1320
end
1421

1522
def show

0 commit comments

Comments
 (0)