diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-01-13 09:10:20 -1000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-01-13 09:10:20 -1000 |
| commit | cb9577d586d9cb324b042a0c05d97d231f9c2e75 (patch) | |
| tree | fb3d644cb9db28b0110bdab421a69ef480b49dc4 /internal/store/sqlite.go | |
| parent | fc4a3a0ea9a10c91b01f2b4e3857b367cb03ed78 (diff) | |
Implement Trello smart sorting by newest card activity
- Update GetBoards SQL query with LEFT JOIN and GROUP BY
- Sort by: 1) Has cards, 2) Newest card (MAX ID), 3) Board name
- Update GetBoardsWithCards to match SQL sorting behavior
- Leverage Trello ID chronological sortability (newer > older)
- Active boards with recent activity appear first
- All tests passing
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/store/sqlite.go')
| -rw-r--r-- | internal/store/sqlite.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/store/sqlite.go b/internal/store/sqlite.go index 5063336..fa8f2b1 100644 --- a/internal/store/sqlite.go +++ b/internal/store/sqlite.go @@ -424,13 +424,17 @@ func (s *Store) SaveBoards(boards []models.Board) error { // GetBoards retrieves all boards with their cards from the database func (s *Store) GetBoards() ([]models.Board, error) { - // Fetch boards, sorted by: non-empty boards first, then alphabetical + // Fetch boards, sorted by: non-empty boards first, newest card activity, then alphabetical + // Trello card IDs are chronologically sortable (newer IDs > older IDs) boardRows, err := s.db.Query(` SELECT b.id, b.name FROM boards b + LEFT JOIN cards c ON c.board_id = b.id + GROUP BY b.id, b.name ORDER BY - CASE WHEN (SELECT COUNT(*) FROM cards c WHERE c.board_id = b.id) > 0 THEN 0 ELSE 1 END, - b.name + CASE WHEN COUNT(c.id) > 0 THEN 0 ELSE 1 END, + MAX(c.id) DESC, + b.name ASC `) if err != nil { return nil, err |
