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/api | |
| 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/api')
| -rw-r--r-- | internal/api/trello.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/internal/api/trello.go b/internal/api/trello.go index b9391d6..c78ebc8 100644 --- a/internal/api/trello.go +++ b/internal/api/trello.go @@ -217,13 +217,39 @@ func (c *TrelloClient) GetBoardsWithCards(ctx context.Context) ([]models.Board, wg.Wait() - // Sort boards: Non-empty boards first, then alphabetical by name + // Sort boards: Non-empty boards first, newest card activity, then alphabetical by name + // Trello card IDs are chronologically sortable (newer IDs > older IDs) sort.Slice(boards, func(i, j int) bool { hasCardsI := len(boards[i].Cards) > 0 hasCardsJ := len(boards[j].Cards) > 0 + + // 1. Prioritize boards with cards if hasCardsI != hasCardsJ { return hasCardsI // true (non-empty) comes before false } + + // 2. If both have cards, compare by newest card (max ID) + if hasCardsI && hasCardsJ { + maxIDI := "" + for _, card := range boards[i].Cards { + if maxIDI == "" || card.ID > maxIDI { + maxIDI = card.ID + } + } + + maxIDJ := "" + for _, card := range boards[j].Cards { + if maxIDJ == "" || card.ID > maxIDJ { + maxIDJ = card.ID + } + } + + if maxIDI != maxIDJ { + return maxIDI > maxIDJ // Newer (larger) ID comes first + } + } + + // 3. Fallback to alphabetical by name return boards[i].Name < boards[j].Name }) |
