Commit 7145697
committed
Updated preference init to skip redundant write
Persistable stores Preferable preferences in a YAML-serialized column.
The initialize_preference_defaults callback ran on every load and
reassigned the preferences attribute even when the merged defaults
already matched the stored value. That assignment switches the attribute
to ActiveModel's "from user" state, whose reads round-trip the hash
through YAML on every access, while "from database" reads only load it.
Hot paths that read calculator preferences per record paid this on every
request. Shipping-rate estimation, for example, reads each shipping
method's calculator preferences and re-dumped YAML once per method per
estimation.
Guard the assignment so it only runs when the merge actually changes the
stored preferences. Unchanged records stay on the cheaper read path and
defaults are still backfilled when missing.1 parent 8d781ac commit 7145697
2 files changed
Lines changed: 15 additions & 3 deletions
File tree
- core
- app/models/concerns/spree/preferences
- spec/models/spree/preferences
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
390 | 401 | | |
391 | 402 | | |
392 | 403 | | |
| |||
0 commit comments