fix(config): cache read no mutation#1256
Open
mvanhorn wants to merge 1 commit intofloatpane:masterfrom
Open
Conversation
Closes floatpane#1251 GetCachedEmailBody is a read operation but updated LastAccessedAt and rewrote the cache file on every hit, violating the read-doesn't-mutate boundary called out in floatpane#1251. main.go calls GetCachedEmailBody twice per email view (in UpdatePreviewMsg and ViewEmailMsg) and both call sites already chase the cached read with SaveEmailBody, which is the function responsible for stamping LastAccessedAt and persisting. Removing the duplicate work here also removes one disk write per email view. Drops the two lines flagged in the issue (config/cache.go:505-506) and adds a one-line note above the function pointing readers at SaveEmailBody as the access-time owner.
floatpanebot
previously requested changes
May 8, 2026
Member
floatpanebot
left a comment
There was a problem hiding this comment.
Hi @mvanhorn! Please fix the following issues with your PR:
- Title: Is too long (76 characters). The PR title must be strictly under 40 characters.
Formatting issues have been resolved. Thank you!
mavonx
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Closes #1251
GetCachedEmailBodyis a read operation but it was stampingLastAccessedAton 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 thatSaveEmailBodyis the access-time owner.Why?
The issue's analysis is correct: every email view path in
main.goalready chasesGetCachedEmailBodywithSaveEmailBody, which setsLastAccessedAt = time.Now()on the entry it persists. That keeps the LRU-style eviction inevict(sorted byLastAccessedAt) 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 returnsPreviewBodyFetchedMsg{Err: nil}. The handler atmain.go:746-779runsconfig.SaveEmailBodywhenevermsg.Err == nil, which updatesLastAccessedAt(config/cache.go:552).main.go:1247-1278(ViewEmailMsg): cache hit returnsEmailBodyFetchedMsg{Err: nil}. The handler atmain.go:1282-1328runsconfig.SaveEmailBodywhenevermsg.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 insideGetCachedEmailBody.Tests
go build ./...cleango test ./...passes (config, daemon, daemonclient, daemonrpc, fetcher, internal/httpclient, internal/threading, pgp, plugin, sender, tui, view all green)go vet ./...cleangofmt -l config/cache.goclean