Commit d6ea21b
The index reads every plan's tags once, not once per plan (#200)
The last thing #196 left on the table. Its location preload had to count
only the location tables, because counting everything would have failed
on `tag_names` — which was doing a query a row — and the number would
then have been bumped to whatever made it pass. That note called the
pluck the cause and left it alone. The pluck isn't the cause.
`pluck` on a relation that's already loaded reads the loaded records
instead of querying; it has since Rails 6. So `tag_names` is free on a
plan whose tags are loaded and one query on a plan whose tags aren't,
and the whole story is that the API index never eager-loaded `:tags`.
Five plans, five `Tag Pluck` queries; add `:tags` to the includes and
there are none. Every other list endpoint that reads tags — the
libraries organization API, the workspace index, home, search — already
preloads them, which is why this only ever showed up here.
So: `:tags` joins the index's eager loads, and the comment on tag_names
now says which of its two costs a caller is paying, so the next reader
doesn't re-derive this the way I just did.
The spec is the location one's twin — tag-table query count for thirty
plans equals the count for three, plus the assertion that each plan
still gets its own tags rather than a neighbour's, since a preload can
be cheap and wrong. Both now share the counter as a helper. It fails
without the includes: thirty queries against three.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 0ef95d0 commit d6ea21b
3 files changed
Lines changed: 49 additions & 20 deletions
File tree
- engine/app
- controllers/coplan/api/v1
- models/coplan
- spec/requests/api/v1
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
292 | 295 | | |
293 | 296 | | |
294 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
16 | 33 | | |
17 | 34 | | |
18 | 35 | | |
19 | 36 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 37 | | |
26 | 38 | | |
27 | 39 | | |
28 | 40 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
56 | 82 | | |
57 | 83 | | |
58 | 84 | | |
| |||
0 commit comments