mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-23 22:24:51 +02:00
Trigger background fetch on repo switch only if enough time has passed since the last one
This commit is contained in:
@@ -79,6 +79,16 @@ func (self *BackgroundRoutineMgr) startBackgroundFetch() {
|
|||||||
self.gui.waitForIntro.Wait()
|
self.gui.waitForIntro.Wait()
|
||||||
|
|
||||||
fetch := func() error {
|
fetch := func() error {
|
||||||
|
// Do this on the UI thread so that we don't have to deal with synchronization around the
|
||||||
|
// access of the repo state.
|
||||||
|
self.gui.onUIThread(func() error {
|
||||||
|
// There's a race here, where we might be recording the time stamp for a different repo
|
||||||
|
// than where the fetch actually ran. It's not very likely though, and not harmful if it
|
||||||
|
// does happen; guarding against it would be more effort than it's worth.
|
||||||
|
self.gui.State.LastBackgroundFetchTime = time.Now()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
return self.gui.helpers.AppStatus.WithWaitingStatusImpl(self.gui.Tr.FetchingStatus, func(gocui.Task) error {
|
return self.gui.helpers.AppStatus.WithWaitingStatusImpl(self.gui.Tr.FetchingStatus, func(gocui.Task) error {
|
||||||
return self.backgroundFetch()
|
return self.backgroundFetch()
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazycore/pkg/boxlayout"
|
"github.com/jesseduffield/lazycore/pkg/boxlayout"
|
||||||
@@ -253,6 +254,8 @@ type GuiRepoState struct {
|
|||||||
ScreenMode types.ScreenMode
|
ScreenMode types.ScreenMode
|
||||||
|
|
||||||
CurrentPopupOpts *types.CreatePopupPanelOpts
|
CurrentPopupOpts *types.CreatePopupPanelOpts
|
||||||
|
|
||||||
|
LastBackgroundFetchTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ types.IRepoStateAccessor = new(GuiRepoState)
|
var _ types.IRepoStateAccessor = new(GuiRepoState)
|
||||||
@@ -308,7 +311,9 @@ func (self *GuiRepoState) GetSplitMainPanel() bool {
|
|||||||
func (gui *Gui) onSwitchToNewRepo(startArgs appTypes.StartArgs, contextKey types.ContextKey) error {
|
func (gui *Gui) onSwitchToNewRepo(startArgs appTypes.StartArgs, contextKey types.ContextKey) error {
|
||||||
err := gui.onNewRepo(startArgs, contextKey)
|
err := gui.onNewRepo(startArgs, contextKey)
|
||||||
if err == nil && gui.UserConfig().Git.AutoFetch && gui.UserConfig().Refresher.FetchInterval > 0 {
|
if err == nil && gui.UserConfig().Git.AutoFetch && gui.UserConfig().Refresher.FetchInterval > 0 {
|
||||||
gui.BackgroundRoutineMgr.triggerImmediateFetch()
|
if time.Since(gui.State.LastBackgroundFetchTime) > gui.UserConfig().Refresher.FetchIntervalDuration() {
|
||||||
|
gui.BackgroundRoutineMgr.triggerImmediateFetch()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user