Commit 19149a6
authored
fix(config): cache read no mutation (#1256)
## What?
Closes #1251
`GetCachedEmailBody` is a read operation but it was stamping
`LastAccessedAt` on the matched entry and rewriting the body cache file
on every hit, violating the read/write boundary the issue calls out.
Drops the two flagged lines (`config/cache.go:505-506`) and adds a
one-line note above the function that `SaveEmailBody` is the access-time
owner.
## Why?
The issue's analysis is correct: every email view path in `main.go`
already chases `GetCachedEmailBody` with `SaveEmailBody`, which sets
`LastAccessedAt = time.Now()` on the entry it persists. That keeps the
LRU-style eviction in `evict` (sorted by `LastAccessedAt`) working
unchanged, with one fewer disk write per email view.
I traced both call sites to verify eviction recency is preserved on
cache hits:
- `main.go:707-744` (UpdatePreviewMsg): cache hit returns
`PreviewBodyFetchedMsg{Err: nil}`. The handler at `main.go:746-779` runs
`config.SaveEmailBody` whenever `msg.Err == nil`, which updates
`LastAccessedAt` (`config/cache.go:552`).
- `main.go:1247-1278` (ViewEmailMsg): cache hit returns
`EmailBodyFetchedMsg{Err: nil}`. The handler at `main.go:1282-1328` runs
`config.SaveEmailBody` whenever `msg.Err == nil`, same path.
So an email the user repeatedly opens still bumps to the front of the
eviction queue on every open; the work just happens in `SaveEmailBody`
(which already exists) instead of duplicating it inside
`GetCachedEmailBody`.1 parent f6f120b commit 19149a6
1 file changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| 498 | + | |
| 499 | + | |
498 | 500 | | |
499 | 501 | | |
500 | 502 | | |
501 | 503 | | |
502 | 504 | | |
503 | 505 | | |
504 | 506 | | |
505 | | - | |
506 | | - | |
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
| |||
0 commit comments