Commit 3ff490f
committed
refactor: optimize json parsing in pydantic schemas
Optimized `parse_pokemon_types` by adding a private `_parse_types_json` helper decorated with `@functools.lru_cache(maxsize=1024)`. The helper returns an immutable tuple to prevent cache pollution and the public function casts it back to a list. This significantly speeds up repeated parsing of identical JSON strings, which is common when processing lists of Pokemon.1 parent 3d1663c commit 3ff490f
1 file changed
Lines changed: 29 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
8 | 36 | | |
9 | 37 | | |
10 | 38 | | |
| |||
19 | 47 | | |
20 | 48 | | |
21 | 49 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 50 | + | |
29 | 51 | | |
30 | 52 | | |
31 | 53 | | |
| |||
0 commit comments