Repository navigation
Commit 6d0cbf4
authored
perf(platform): index approved OAuth assets by content tuple (#556)
## Issue
OAuth upload validation currently scans every approved asset for each
requested asset while holding the project lock. At the allowed
5,000-asset batch size, this can require millions of comparisons.
## Fix
This reduces validation from O(approved × requested) to expected
O(approved + requested).
Build a `Set` of approved `(blake3, md5, size)` tuples, using a local
`assetApprovalKey()` helper with `JSON.stringify` for both indexing and
lookup. Project matching and exact matching of all three fields are
preserved.
## Benchmark results
12 paired runs on Apple M2 Pro, Node v24.21.0. Validation timings
include Set construction and JSON encoding; database, presigning, and
network I/O are excluded.
| Approved assets | Requested assets | Before | After | % reduction |
| --- | --- | --- | --- | --- |
| 100 | 100 | 0.084 ms | 0.051 ms | 39.1% |
| 5,000 | 100 | 4.721 ms | 2.082 ms | 55.9% |
| 5,000 | 1,000 | 40.969 ms | 2.317 ms | 94.3% |
| 5,000 | 5,000 | **227.016 ms** | **3.340 ms** | **98.5%** |
| 20,000 | 5,000 | 808.418 ms | 10.352 ms | 98.7% |
The 5,000/5,000 case is about **68× faster**.
## Why the tests changed
Expanded coverage verifies multiple approved assets, reordered batches,
duplicates, mismatched fields, mixed valid/invalid batches, and strict
field types (`"3"` versus `3`). **All 19 tests pass against both the
original and optimized implementations.**
## Verification
Typechecking passed; 4,447 affected tests and 14,496 full-suite tests
passed.1 parent dbbdcd3 commit 6d0cbf4
2 files changed
Lines changed: 33 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
167 | 176 | | |
168 | 177 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 178 | + | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
211 | 217 | | |
212 | 218 | | |
213 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
214 | 229 | | |
215 | 230 | | |
216 | 231 | | |
| |||
222 | 237 | | |
223 | 238 | | |
224 | 239 | | |
225 | | - | |
| 240 | + | |
226 | 241 | | |
227 | 242 | | |
228 | 243 | | |
229 | | - | |
| 244 | + | |
230 | 245 | | |
231 | 246 | | |
| 247 | + | |
232 | 248 | | |
| 249 | + | |
233 | 250 | | |
| 251 | + | |
| 252 | + | |
234 | 253 | | |
235 | 254 | | |
236 | 255 | | |
| |||
0 commit comments