Skip to content

fix: clean account caches on deletion#1265

Open
FromSi wants to merge 2 commits into
floatpane:masterfrom
FromSi:fix/cleanup-account-cache-on-delete
Open

fix: clean account caches on deletion#1265
FromSi wants to merge 2 commits into
floatpane:masterfrom
FromSi:fix/cleanup-account-cache-on-delete

Conversation

@FromSi
Copy link
Copy Markdown
Contributor

@FromSi FromSi commented May 8, 2026

What?

This PR updates contact usage tracking and cleans account-owned cache data when an account is deleted.

Commit 1: contact usage per account

Contacts now store usage metadata per account instead of a single global last_used/use_count pair.

Old contact JSON:

{
  "name": "Alice",
  "email": "alice@example.com",
- "last_used": "2026-05-06T19:29:28.502623767+05:00",
- "use_count": 1
}

New contact JSON:

{
  "name": "Alice",
  "email": "alice@example.com",
+ "usage_by_account": {
+   "account-id": {
+     "last_used": "2026-05-06T19:29:28.502623767+05:00",
+     "use_count": 1
+   }
+ }
}

This includes migration support for legacy contacts, account-aware contact search, account-aware contact saving, macOS contact sync updates, and small generic collection helpers.

Commit 2: account cache cleanup

Adds a single config.CleanupAccountCache(accountID) method that removes data associated with a deleted account from:

  • email_cache.json
  • folder_cache.json
  • folder_emails/*.json
  • email_bodies/*.json
  • contacts.json
  • drafts.json

The account deletion flow now calls this cleanup after RemoveAccount.

Why?

Closes: #519

Fixes stale account data being left behind after deleting an account.

Previously, deleting an account removed it from config and deleted credentials from the keyring, but cached emails, cached bodies, drafts, folder cache entries, and contact usage stayed on disk. Over time this left orphaned data in ~/.cache/matcha.

The contact schema change makes it possible to remove only the deleted account’s contact association while preserving shared contacts still used by other accounts.

@FromSi FromSi requested a review from a team as a code owner May 8, 2026 22:56
@floatpanebot floatpanebot added area/tui Terminal UI / view layer area/config Configuration / settings area/cli CLI flags / commands bug Something isn't working chore Maintenance, refactor, cleanup os/macos macOS-specific labels May 8, 2026
@andrinoff
Copy link
Copy Markdown
Member

big PR, i'll check it out later, thx @FromSi

@andrinoff
Copy link
Copy Markdown
Member

I'll review these changes way later, very busy at the moment, won't release the next version without this, so no worries

@andrinoff andrinoff added the size/L Diff: 201–800 lines label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli CLI flags / commands area/config Configuration / settings area/tui Terminal UI / view layer bug Something isn't working chore Maintenance, refactor, cleanup os/macos macOS-specific size/L Diff: 201–800 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Account deletion leaves orphaned cache files

3 participants