Skip to content

fix(media): count whole library for "All Files" total#891

Open
PlusA2M wants to merge 1 commit into
SonicJs-Org:mainfrom
PlusA2M:fix/media-total-count
Open

fix(media): count whole library for "All Files" total#891
PlusA2M wants to merge 1 commit into
SonicJs-Org:mainfrom
PlusA2M:fix/media-total-count

Conversation

@PlusA2M

@PlusA2M PlusA2M commented Jun 13, 2026

Copy link
Copy Markdown

Description

The Media library sidebar always shows All Files (24) because the GET /admin/media
handler reports the page length as the total. This computes the real total with a
COUNT(*) over the same filters.

Fixes #888

Changes

  • admin-media.ts GET /: add a COUNT(*) over the same folder/type conditions
    (without LIMIT/OFFSET) and use it for totalFiles.
  • Compute hasNextPage from offset + results.length < totalFiles instead of
    comparing the page length to the limit.
  • Add a regression test asserting the total comes from COUNT(*) (not the page
    size), that folder/type filters flow into the count query, and that
    hasNextPage is false on the last page.

Testing

Unit Tests

  • Added/updated unit tests (admin-media-total-count.test.ts)
  • All unit tests passing (npm test — full suite green)

E2E Tests

  • Added/updated E2E tests
  • All E2E tests passing

Checklist

  • Code follows project conventions
  • Tests added/updated and passing
  • Type checking passes
  • No console errors or warnings
  • Documentation updated (if needed) — n/a

GET /admin/media reported `totalFiles: results.length`, but `results` is a
single page (LIMIT 24), so the sidebar always read "All Files (24)" and
`hasNextPage` compared the page length to the limit. Add a COUNT(*) over the
same folder/type filters and derive the total and pagination from it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: PlusA2M <plusa2m@gmail.com>
@PlusA2M PlusA2M requested a review from lane711 as a code owner June 13, 2026 16:30
@lane711

lane711 commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this fix! We're in the process of merging v3 to main — v3 has migrated the media module to a document model architecture (MediaDocumentService), so admin-media.ts no longer queries the legacy media table directly. The totalFiles bug you identified does exist in v3, but the fix needs to go into MediaDocumentService.list() to return a real total count alongside the page results. We'll track this as a v3 issue and fix it natively. Really appreciate the detailed PR and regression test — it made diagnosing the v3 equivalent much easier.

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.

Media library "All Files" count shows the page size (24), not the library total

2 participants