Commit 5abaffc
authored
Add a project_identifier parameter to LessonController#index (#649)
Experience CS was calling `LessonsController#index` on almost every
Scratch project load, pulling the entire set of Lesson data between the
two systems, and then filtering that array on the Experience CS side to
find a lesson that matched a project identifier.
This commit allows passing a `project_identifier` query parameter to
`LessonsController#show` that will allow Experience CS to query directly
for the lesson it needs.
## Status
- Related to RaspberryPiFoundation/experience-cs#1002 (see [this
comment](RaspberryPiFoundation/experience-cs#1002 (comment)))
## Points for consideration:
- Performance: this change should allow us to make a change in
Experience CS that will massively cut the amount of data being shifted
between the two systems.
## What's changed?
I refactored `LessonsController#index` to further narrow the scope to
projects where a `project_identifier` query parameter was present in the
request. I refactored it to keep Rubocop happy but, essentially, I just
added the line:
`scope = scope.joins(:project).where(projects: { identifier:
params[:project_identifier] }) if params[:project_identifier].present?`
...to the calculation of the scope of Lessons to return.
## Steps to perform after deploying to production
No additional steps required.1 parent 439975d commit 5abaffc
2 files changed
Lines changed: 54 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
15 | 13 | | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
135 | 178 | | |
136 | 179 | | |
137 | 180 | | |
| |||
0 commit comments