Repository navigation
Commit 6b8db7f
Avoid per-row queries for evolution condition variables and natures (#1690)
* Load evolution variables and natures once per list of evolution details
get_condition_expression and get_allowed_natures ran a query per
PokemonEvolution row. Milcery -> Alcremie has 63 rows, each with a
condition_expression, so its evolution chain took 65 queries.
Both tables are tiny (4 evolution variables, 25 natures), so load each
once, lazily, on the serializer instance. A ListSerializer reuses its
child instance for every row, so this is one query per list instead of
one per row, without sharing state across requests.
* Cache serialized evolution variables and natures, not just the rows
The cached lookups still ran the summary serializers once per
evolution row. Serialize each table once alongside the query and reuse
the results; serializing Alcremie's chain (63 rows) drops from ~52 ms
to ~32 ms locally with identical output.
Variables are kept as (symbol, data) pairs instead of a dict, since
symbol isn't unique across version groups.
* Remove comment
---------
Co-authored-by: Alessandro Pezzè <igougi.ui@gmail.com>1 parent 8c426c4 commit 6b8db7f
2 files changed
Lines changed: 71 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
3429 | 3430 | | |
3430 | 3431 | | |
3431 | 3432 | | |
| 3433 | + | |
| 3434 | + | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
| 3438 | + | |
| 3439 | + | |
| 3440 | + | |
| 3441 | + | |
| 3442 | + | |
| 3443 | + | |
| 3444 | + | |
3432 | 3445 | | |
3433 | 3446 | | |
3434 | 3447 | | |
3435 | 3448 | | |
3436 | | - | |
| 3449 | + | |
3437 | 3450 | | |
3438 | 3451 | | |
3439 | | - | |
3440 | | - | |
3441 | | - | |
3442 | | - | |
3443 | | - | |
| 3452 | + | |
3444 | 3453 | | |
3445 | 3454 | | |
3446 | 3455 | | |
3447 | 3456 | | |
3448 | 3457 | | |
3449 | | - | |
3450 | | - | |
| 3458 | + | |
3451 | 3459 | | |
3452 | 3460 | | |
3453 | 3461 | | |
3454 | | - | |
| 3462 | + | |
3455 | 3463 | | |
3456 | 3464 | | |
3457 | 3465 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
5053 | 5054 | | |
5054 | 5055 | | |
5055 | 5056 | | |
| 5057 | + | |
| 5058 | + | |
| 5059 | + | |
| 5060 | + | |
| 5061 | + | |
| 5062 | + | |
| 5063 | + | |
| 5064 | + | |
| 5065 | + | |
| 5066 | + | |
| 5067 | + | |
| 5068 | + | |
| 5069 | + | |
| 5070 | + | |
| 5071 | + | |
| 5072 | + | |
| 5073 | + | |
| 5074 | + | |
| 5075 | + | |
| 5076 | + | |
| 5077 | + | |
| 5078 | + | |
| 5079 | + | |
| 5080 | + | |
| 5081 | + | |
| 5082 | + | |
| 5083 | + | |
| 5084 | + | |
| 5085 | + | |
| 5086 | + | |
| 5087 | + | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
| 5094 | + | |
| 5095 | + | |
| 5096 | + | |
| 5097 | + | |
| 5098 | + | |
| 5099 | + | |
| 5100 | + | |
| 5101 | + | |
| 5102 | + | |
| 5103 | + | |
| 5104 | + | |
| 5105 | + | |
| 5106 | + | |
| 5107 | + | |
| 5108 | + | |
| 5109 | + | |
5056 | 5110 | | |
5057 | 5111 | | |
5058 | 5112 | | |
| |||
0 commit comments