summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-01-12 13:23:55 -1000
committerPeter Stone <thepeterstone@gmail.com>2026-01-12 13:23:55 -1000
commit80c233287b65927a012ff46a27d4eac9a796fce0 (patch)
treeec69f26c116274b69b5d5c200e4a563f2bdc8445 /internal
parent325811c369b77b0a6b15bf81463948a10cb1f658 (diff)
Parallelize Trello card fetching for improved performance
Replaced sequential card fetching in GetBoardsWithCards with concurrent goroutines limited by a semaphore (max 5 concurrent requests). This significantly reduces load times for users with multiple boards. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/api/trello.go27
1 files changed, 20 insertions, 7 deletions
diff --git a/internal/api/trello.go b/internal/api/trello.go
index 899f6df..cecf0dc 100644
--- a/internal/api/trello.go
+++ b/internal/api/trello.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
+ "sync"
"time"
"task-dashboard/internal/models"
@@ -193,16 +194,28 @@ func (c *TrelloClient) GetBoardsWithCards(ctx context.Context) ([]models.Board,
return nil, err
}
- // Fetch cards for each board
+ var wg sync.WaitGroup
+ sem := make(chan struct{}, 5) // Limit to 5 concurrent requests
+
for i := range boards {
- cards, err := c.GetCards(ctx, boards[i].ID)
- if err != nil {
- // Log error but continue with other boards
- continue
- }
- boards[i].Cards = cards
+ wg.Add(1)
+ go func(i int) {
+ defer wg.Done()
+
+ // Acquire semaphore
+ sem <- struct{}{}
+ defer func() { <-sem }()
+
+ cards, err := c.GetCards(ctx, boards[i].ID)
+ if err == nil {
+ // It is safe to write to specific indices of the slice concurrently
+ boards[i].Cards = cards
+ }
+ }(i)
}
+ wg.Wait()
+
return boards, nil
}