feat: optimized board queries
Summary
In #6603 I made some changes to reduce SQL queries and network requests when listing boards. That PR got crusty, this PR updates it to work on main.
Two main changes.
feat(app): add method & route to get uncategorized image counts
Previously we were abusing the list boards query (twice!) to get the counts for uncategorized images/assets. There is now a dedicated endpoint for this.
feat(app): optimize boards queries
Use SQL instead of python to retrieve image count, asset count and board cover image.
This reduces the number of SQL queries needed to list all boards. Previously, we did
1 + 2 * board_countqueries::
- 1 query to get the list of board records
- 1 query per board to get its total count
- 1 query per board to get its cover image
Then, on the frontend, we made two additional network requests to get each board's counts:
- 1 request (== 1 SQL query) for image count
- 1 request (== 1 SQL query) for asset count
All of this information is now retrieved in a single SQL query, and provided via single network request.
As part of this change,
BoardRecordnow includesimage_count,asset_countandcover_image_name. This makesBoardDTOredundant, but removing it is a deeper change...
Related Issues / Discussions
- Supersedes #6603 (this is that PR, but updated for
main)
QA Instructions
Needs re-review from @maryhipp.
Board counts should be correct and update as images are moved between boards and generated/saved to gallery.
Merge Plan
This should only be merged after v5 is released.
Checklist
- [x] The PR has a short but descriptive title, suitable for a changelog
- [ ] Tests added / updated (if applicable)
- [ ] Documentation added / updated (if applicable)