8000 Fetch a message's attachments once, not once per Gmail label by typedev · Pull Request #112 · hyprlab/hylki · GitHub
[go: up one dir, main page]

Skip to content

Fetch a message's attachments once, not once per Gmail label - #112

Closed
typedev wants to merge 1 commit into
hyprlab:mainfrom
typedev:fix/attachments-fetched-once-per-message
Closed

typedev wants to merge 1 commit into
hyprlab:mainfrom
typedev:fix/attachments-fetched-once-per-message

Conversation

@typedev
@typedev typedev commented Sep 2, 2026
Copy link
Copy Markdown
Contributor

Fixes #111.

Gmail shows one message under every label it carries, so the same mail arrives as INBOX + a label + All Mail. load_attachments already reads across those copies — attachments_downloaded_under_one_label_answer_for_the_others covers it — but attachments_checked still keyed strictly on (account, folder, uid), and queue_attachment_prefetch asks that one.

So each label looked unfetched: the whole message was downloaded again, and save_attachments wrote another full copy of the blobs under that folder. A message under three labels costs three downloads and three copies on disk for one message's files. The reader never shows them, because the read side already reaches across.

The change

pub fn attachments_checked(&self, account_id: u32, folder_path: &str, uid: u32) -> bool {
    if self.checked_of(account_id, folder_path, uid) {
        return true;
    }
    self.sibling_copies(account_id, folder_path, uid)
        .into_iter()
        .any(|(p, u)| self.checked_of(account_id, &p, u))
}

The body query moves to a private checked_of, unchanged. No new helper and no new SQL — this is the same sibling_copies the body and attachment read paths already use.

Symmetry with bodies

run_one_body_prefetch asks load_body before it connects, and load_body reads across labels, so a sibling's cached body ends the fetch before any network work. The attachment path was the same shape with that step missing. After this change both halves agree.

Tests

  • attachments_fetched_under_one_label_count_as_fetched_for_the_others — one message under two labels, marked fetched under one, reads as fetched under the other.
  • another_message_being_fetched_does_not_count_as_this_one — a different message under a label does not count, because sibling_copies requires Message-ID, sender and timestamp to match.

Full suite: 249 passed, 0 failed.

Note

This stops new duplicates. Copies already written by an earlier build stay until something clears them — a one-time sweep on upgrade would reclaim that space, happy to add it here or separately, whichever you prefer.

Gmail shows one message under every label it carries, so the same mail
arrives as INBOX + a label + All Mail. `load_attachments` already reads
across those copies — `attachments_downloaded_under_one_label_answer_for_the_others`
covers it — but `attachments_checked` still keyed strictly on
(account, folder, uid).

So the prefetch saw each label as unfetched and downloaded the whole message
once per label, then stored a second and third copy of blobs it could already
answer from. A message under three labels costs three full downloads and three
copies on disk for one message's files.

Bodies already avoid this: `run_one_body_prefetch` asks `load_body` first, and
that reads across labels, so a sibling's body ends the fetch. This gives the
attachment path the same reach, through the same `sibling_copies` helper, so
both halves of the rule agree.

The reach stops where `sibling_copies` stops — a matching Message-ID plus
sender and timestamp — so an unrelated message never counts as fetched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
hyprlab added a commit that referenced this pull request Sep 3, 2026
Gmail shows one message under every label it carries, so the same mail
arrives as INBOX + a label + All Mail. `load_attachments` already reads
across those copies — `attachments_downloaded_under_one_label_answer_for_the_others`
covers it — but `attachments_checked` still keyed strictly on
(account, folder, uid).

So the prefetch saw each label as unfetched and downloaded the whole message
once per label, then stored a second and third copy of blobs it could already
answer from. A message under three labels costs three full downloads and three
copies on disk for one message's files.

Bodies already avoid this: `run_one_body_prefetch` asks `load_body` first, and
that reads across labels, so a sibling's body ends the fetch. This gives the
attachment path the same reach, through the same `sibling_copies` helper, so
both halves of the rule agree.

The reach stops where `sibling_copies` stops — a matching Message-ID plus
sender and timestamp — so an unrelated message never counts as fetched.

Landed from #112.

Co-Authored-By: Alexander Lubovenko <2742734+typedev@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ay7c8wSGyaTPNuDXShNgAw
hyprlab added a commit that referenced this pull request Sep 3, 2026
The two previous commits stop new damage; this heals what earlier builds
already wrote. Mail synced before them has attachment lists that are wrong
in place — small declared files missing (#109), blobs stored once per Gmail
label (#111) — and `attachments_checked` remembers those messages as done,
so `queue_attachment_prefetch` would never touch them again and the wrong
lists would survive forever.

Bump the cache schema to v13 and drop `attachments` and
`attachments_checked` on upgrade. The re-fetch is bounded: the prefetch
re-touches only the newest 25 flagged messages per folder, and everything
else heals lazily when a message is opened, since `LoadAttachments` fetches
on demand. Dropping the blobs also reclaims the per-label duplicate copies
in one stroke.

Suggested in #110 and #112.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ay7c8wSGyaTPNuDXShNgAw
hyprlab added a commit that referenced this pull request Sep 3, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ay7c8wSGyaTPNuDXShNgAw
hyprlab added a commit that referenced this pull request Sep 3, 2026
…andles

Feature beta previewing 1.20.0. See CHANGELOG.md for the full list:
composer spell checking with bundled dictionaries and a managed
personal word list (discussion #114), inline images in the composer
(discussion #113), replies that follow Reply-To, the split reply and
attachment drawer resized by a floating grab pill, paste-as-plain-text
by default, the wide-mail scroll fix, and the three attachment fixes
from #110, #112 and #118 with a one-time cache repair.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ay7c8wSGyaTPNuDXShNgAw
@hyprlab
hyprlab commented Sep 4, 2026
Copy link
Copy Markdown
Owner

Landed in stable 1.20.0 as commit e10f6ee on main, with you as co-author. Thank you. Applied as written. Closing since the commit is on main rather than merged from the branch.

@hyprlab hyprlab closed this Sep 4, 2026
@typedev
typedev deleted the fix/attachments-fetched-once-per-message branch September 17, 2026 19:32
hyprlab added a commit that referenced this pull request Sep 24, 2026
…andles

Feature beta previewing 1.20.0. See CHANGELOG.md for the full list:
composer spell checking with bundled dictionaries and a managed
personal word list (discussion #114), inline images in the composer
(discussion #113), replies that follow Reply-To, the split reply and
attachment drawer resized by a floating grab pill, paste-as-plain-text
by default, the wide-mail scroll fix, and the three attachment fixes
from #110, #112 and #118 with a one-time cache repair.
somepaulo pushed a commit to somepaulo/hylki that referenced this pull request Sep 24, 2026
Gmail shows one message under every label it carries, so the same mail
arrives as INBOX + a label + All Mail. `load_attachments` already reads
across those copies — `attachments_downloaded_under_one_label_answer_for_the_others`
covers it — but `attachments_checked` still keyed strictly on
(account, folder, uid).

So the prefetch saw each label as unfetched and downloaded the whole message
once per label, then stored a second and third copy of blobs it could already
answer from. A message under three labels costs three full downloads and three
copies on disk for one message's files.

Bodies already avoid this: `run_one_body_prefetch` asks `load_body` first, and
that reads across labels, so a sibling's body ends the fetch. This gives the
attachment path the same reach, through the same `sibling_copies` helper, so
both halves of the rule agree.

The reach stops where `sibling_copies` stops — a matching Message-ID plus
sender and timestamp — so an unrelated message never counts as fetched.

Landed from hyprlab#112.

Co-Authored-By: Alexander Lubovenko <2742734+typedev@users.noreply.github.com>
somepaulo pushed a commit to somepaulo/hylki that referenced this pull request Sep 24, 2026
The two previous commits stop new damage; this heals what earlier builds
already wrote. Mail synced before them has attachment lists that are wrong
in place — small declared files missing (hyprlab#109), blobs stored once per Gmail
label (hyprlab#111) — and `attachments_checked` remembers those messages as done,
so `queue_attachment_prefetch` would never touch them again and the wrong
lists would survive forever.

Bump the cache schema to v13 and drop `attachments` and
`attachments_checked` on upgrade. The re-fetch is bounded: the prefetch
re-touches only the newest 25 flagged messages per folder, and everything
else heals lazily when a message is opened, since `LoadAttachments` fetches
on demand. Dropping the blobs also reclaims the per-label duplicate copies
in one stroke.

Suggested in hyprlab#110 and hyprlab#112.
somepaulo pushed a commit to somepaulo/hylki that referenced this pull request Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A labelled Gmail message has its attachments downloaded and stored once per label

2 participants

0