Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions internal/tui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ func Run(cfg *config.Config) error {
}

// scanReposCmd is a command that scans for repositories
func scanReposCmd(cfg *config.Config) tea.Cmd {
// If forceRefresh is true, bypass cache and scan fresh
func scanReposCmd(cfg *config.Config, forceRefresh bool) tea.Cmd {
return func() tea.Msg {
// Try to load from cache first
cacheStore := cache.NewFileStore()
cached, err := cacheStore.Load()

if err == nil && cacheStore.IsValid(cacheMaxAge) && cacheStore.IsSameRoots(cfg.Roots) {
// Use cached data but trigger background refresh
return scanCompleteMsg{
repos: cached.Repos,
fromCache: true,
// Try to load from cache first (unless forcing refresh)
if !forceRefresh {
cached, err := cacheStore.Load()
if err == nil && cacheStore.IsValid(cacheMaxAge) && cacheStore.IsSameRoots(cfg.Roots) {
return scanCompleteMsg{
repos: cached.Repos,
fromCache: true,
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func NewModel(cfg *config.Config) Model {

// Init initializes the model
func (m Model) Init() tea.Cmd {
return tea.Batch(m.spinner.Tick, scanReposCmd(m.cfg))
return tea.Batch(m.spinner.Tick, scanReposCmd(m.cfg, false))
}

// GetSelectedRepo returns the currently selected repo
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} else {
m.statusMsg = ""
}
return m, scanReposCmd(m.cfg)
return m, scanReposCmd(m.cfg, true)

case grassDataLoadedMsg:
m.grassData = msg.data
Expand Down Expand Up @@ -182,7 +182,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "r":
m.state = StateLoading
m.statusMsg = "Rescanning..."
return m, scanReposCmd(m.cfg)
return m, scanReposCmd(m.cfg, true)

case "f":
// Cycle through filter modes
Expand Down