Skip to content

fix: show real storage metrics in Storage Usage screen - #34

Merged
bisonbet merged 3 commits into
mainfrom
codex/fix-missing-documents-in-tab
Apr 15, 2026
Merged

fix: show real storage metrics in Storage Usage screen#34
bisonbet merged 3 commits into
mainfrom
codex/fix-missing-documents-in-tab

Conversation

@bisonbet

Copy link
Copy Markdown
Owner

Motivation

  • The Storage Usage screen used hard-coded mock values (including a fixed "25 documents") which could mislead users when the Documents tab was actually empty.
  • Update the storage screen to report live on-device metrics so storage diagnostics reflect the real state of the app.

Description

  • Replaced simulated storage data and artificial delay in StorageUsageView with real metrics fetched from FileSystemManager and DatabaseManager, and added a lightweight error UI to surface load failures (HealthApp/HealthApp/Views/StorageUsageView.swift).
  • Added two new helper methods to DatabaseManager to estimate payload sizes for health data and chat messages (getHealthDataPayloadSizeEstimate() and getChatPayloadSizeEstimate()) used by the storage screen (HealthApp/HealthApp/Database/DatabaseManager.swift).
  • Combined file-system size (documents/thumbnails/exports/logs), document count, conversation count, and payload size estimates into the StorageInfo model so the UI shows a real breakdown instead of placeholders.
  • Added error handling and logging so failures produce a friendly message in the Storage screen and an error entry in the app log instead of showing static numbers.

Testing

  • Ran git diff --check to validate there are no trivial formatting or whitespace issues and it passed.
  • Performed automated repository searches to verify the mocked literals and the simulated Task.sleep were removed from StorageUsageView, and those checks succeeded.
  • No unit or UI test suite run was requested during this change.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8865123e45

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +119 to +123
async let fileSystemUsage = FileSystemManager.shared.getStorageUsage()
async let documentCount = DatabaseManager.shared.getDocumentCount()
async let chatStats = DatabaseManager.shared.getChatStatistics()
async let healthDataPayloadSize = DatabaseManager.shared.getHealthDataPayloadSizeEstimate()
async let chatPayloadSize = DatabaseManager.shared.getChatPayloadSizeEstimate()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Offload storage scans from the main actor

This async let block looks concurrent, but each call targets @MainActor singletons (FileSystemManager and DatabaseManager), so the underlying synchronous I/O still runs on the UI actor. In particular, getStorageUsage() walks every file and the new SUM(LENGTH(...)) queries scan entire tables, which can stall rendering/interaction when users have many documents or messages; please move these storage/database calculations to a background actor/queue and only hop back to update @State.

Useful? React with 👍 / 👎.

@bisonbet

Copy link
Copy Markdown
Owner Author

@claude review this PR

@claude

claude Bot commented Apr 15, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

bisonbet and others added 2 commits April 15, 2026 19:09
Both getHealthDataPayloadSizeEstimate() and getChatPayloadSizeEstimate()
were implicitly @mainactor (inherited from DatabaseManager), causing
table-wide SUM(LENGTH()) scans to block the main thread. Use
withCheckedThrowingContinuation + DispatchQueue.global to suspend the
main actor during the query and resume on completion.

Addresses Codex P2 review comment on PR #34.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Storage Usage screen called four @mainactor methods synchronously,
blocking the UI thread during directory walks and table-wide DB scans:

- FileSystemManager.getStorageUsage(): 4 directory walks → background
- DatabaseManager.getDocumentCount(): DB scalar → background
- DatabaseManager.getChatStatistics(): 5 DB scalars → background
- DatabaseManager.getHealthDataPayloadSizeEstimate/getChatPayloadSizeEstimate
  were already fixed in the previous commit

All four now use withCheckedThrowingContinuation + DispatchQueue.global
so the main actor is released while I/O runs, consistent with the
pattern established for the two new DatabaseManager methods.

Also adds a Retry button with full accessibility labels to the error
section introduced by this PR (required per CLAUDE.md).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bisonbet
bisonbet merged commit e902280 into main Apr 15, 2026
1 check passed
@bisonbet
bisonbet deleted the codex/fix-missing-documents-in-tab branch April 15, 2026 23:22
bisonbet added a commit that referenced this pull request Apr 15, 2026
The two storage management buttons were left as stubs after main was
reworked to use DatabaseManager methods for live metrics (PRs #34/#35).
clearCache() now calls FileSystemManager.shared.clearCache() and
optimizeStorage() calls cleanupOldThumbnails(olderThan: 14) only —
intentionally omitting clearCache() to preserve the semantic distinction
between the two actions (age-based selective cleanup vs. full wipe).
Both actions refresh displayed metrics on completion and surface failures
via the existing lastErrorMessage error state.

Closes #35 (superseded — all review issues now addressed on main)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant