Commit 3f0bc74
committed
perf(Admin::PicturesController): Preload deletable ids
Rendering the picture archive used to call Picture#deletable? per row
to decide which delete buttons to show. Each call issued up to two
queries (the polymorphic related_ingredients check and the LIKE scan
for ingredient-value references), so a page of N pictures cost up to
2N extra queries in addition to the main fetch.
The controller now runs the deletable scope once for the ids on the
current page and stores the result in a Set. Because the scope relation
is chained as the subquery source of an IN clause, Rails applies the
same Ransack filter, sort, and pagination on the database side without
materializing the ids Ruby-side, keeping the check tight to the rows
the view actually renders. The same preload is wired to the update
action since it re-renders the picture partial via turbo stream.1 parent bad0ff8 commit 3f0bc74
3 files changed
Lines changed: 42 additions & 3 deletions
File tree
- app
- controllers/alchemy/admin
- views/alchemy/admin/pictures
- spec/controllers/alchemy/admin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
| |||
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | | - | |
34 | | - | |
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| |||
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
162 | 180 | | |
163 | 181 | | |
164 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
139 | 160 | | |
140 | 161 | | |
141 | 162 | | |
| |||
0 commit comments