Version: 2.19.0 (also present on main)
Describe the bug
The Media sidebar always shows All Files (24) regardless of how many media
files exist. The per-folder and per-type counts next to it are correct, and
pagination is also affected (the "Next" control appears/disappears based on the
page length rather than the real total).
Root cause
In packages/core/src/routes/admin-media.ts, the GET / handler runs a
paginated query (… ORDER BY uploaded_at DESC LIMIT 24 OFFSET …) into
results, then reports the total as that page's length:
totalFiles: results.length, // ≤ 24 (the page size)
hasNextPage: results.length === limit,
The handler already issues separate aggregate queries for the folder and type
sidebars, so the total should likewise be a COUNT(*) over the same WHERE
filters (folder/type), without LIMIT/OFFSET.
To reproduce
- Have more than 24 media files.
- Open
/admin/media.
- The sidebar reads All Files (24).
Expected
The sidebar shows the true library total, and hasNextPage is computed against
that total. Applying a folder/type filter should reflect the filtered total.
Proposed fix
Add a COUNT(*) over the same conditions/params the list query already
builds, and derive totalFiles and hasNextPage from it:
const countQuery = `SELECT COUNT(*) as total FROM media WHERE ${conditions.join(' AND ')}`
const countRow = await db.prepare(countQuery).bind(...params).first<{ total: number }>()
const totalFiles = countRow?.total ?? 0
// …
totalFiles,
hasNextPage: offset + results.length < totalFiles,
I have a working fix with a regression test and can open a PR.
Version: 2.19.0 (also present on
main)Describe the bug
The Media sidebar always shows All Files (24) regardless of how many media
files exist. The per-folder and per-type counts next to it are correct, and
pagination is also affected (the "Next" control appears/disappears based on the
page length rather than the real total).
Root cause
In
packages/core/src/routes/admin-media.ts, theGET /handler runs apaginated query (
… ORDER BY uploaded_at DESC LIMIT 24 OFFSET …) intoresults, then reports the total as that page's length:The handler already issues separate aggregate queries for the folder and type
sidebars, so the total should likewise be a
COUNT(*)over the same WHEREfilters (folder/type), without LIMIT/OFFSET.
To reproduce
/admin/media.Expected
The sidebar shows the true library total, and
hasNextPageis computed againstthat total. Applying a folder/type filter should reflect the filtered total.
Proposed fix
Add a
COUNT(*)over the sameconditions/paramsthe list query alreadybuilds, and derive
totalFilesandhasNextPagefrom it:I have a working fix with a regression test and can open a PR.