Commit 45b3c0d
Fix N+1 queries on home page property listings
Before: 83 queries, 579ms response time
After: 28 queries, 278ms response time
Changes:
- Convert sale_listing/rental_listing methods to belongs_to associations
in Pwb::ListedProperty so they can be eager loaded
- Update with_eager_loading scope to include :sale_listing and
:rental_listing associations
The N+1 was caused by sale_listing and rental_listing being methods
that called find_by individually for each property, instead of
associations that could be preloaded in a single query.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 2b88ae8 commit 45b3c0d
File tree
2 files changed
+12
-11
lines changed- app/models
- concerns/listed_property
- pwb
2 files changed
+12
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | 134 | | |
139 | 135 | | |
140 | 136 | | |
| |||
0 commit comments