In order to avoid incurring long startup times, we migrate message schema (data) in the background using `window.requestIdleCallback` API. The migration moves attachment data from IndexedDB to disk and reduces load on our database which may cause data loss (#1589).
On my development profile, this migration reduced the IndexedDB directory from 33.4MB to 4.7MB.
- [x] Generate random file names.
- [x] Generate random file paths that prevent too many files per folder using
fan-out.
- [x] Create attachment directory in user data folder.
- [x] Investigate operating system file indexing on:
- [x] Windows: Confirmed that `AppData` is not indexed by default.
- [x] macOS: Confirmed that `~/Library` files are not indexed by default.
Searching system files using Spotlight requires multi-step opt-in:
https://lifehacker.com/5711409/how-to-search-for-hidden-packaged-and-system-files-in-os-x.
More info https://apple.stackexchange.com/a/92785.
Added `.noindex` suffix to `attachments` folder.
- [x] Linux: n/a
- [x] Save incoming attachment files to disk
- [x] On received
- [x] On sync
- [x] Save outgoing attachments files to disk before sending
- [x] Display attachments either from disk or memory in attachment view.
Be robust to multiple render passes.
- [x] Test that missing attachment on disk doesn’t break app.
Behavior: Message is displayed without attachment.
- [x] Delete attachment files when message is deleted.
Relates to #1589.
Using 2 hex characters [0-9a-f] will give us 16 * 16 = 256 root folders which
seems more manageable than 4096 (16^3). Assuming a user has 10,000 attachments,
they should roughly distribute at ~40 per folder with prefix length 2 rather
than ~2.5 per folder with a prefix of 3.