dirlist: skip unnecessary change-folder action
when traversing the directory list, aerc will fetch the contents for every directory even though the user might just move on to the next. This causes an unnecessary delay (and load on the worker) and can be avoided by skipping the old change-folder action when a newer one arrives within a predefined time interval. Signed-off-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
parent
eafb537081
commit
cb3090956c
1 changed files with 55 additions and 39 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
|
@ -30,6 +31,7 @@ type DirectoryList struct {
|
||||||
scroll int
|
scroll int
|
||||||
spinner *Spinner
|
spinner *Spinner
|
||||||
worker *types.Worker
|
worker *types.Worker
|
||||||
|
skipSelect chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
|
func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
|
||||||
|
@ -41,6 +43,7 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
store: lib.NewDirStore(),
|
store: lib.NewDirStore(),
|
||||||
worker: worker,
|
worker: worker,
|
||||||
|
skipSelect: make(chan bool),
|
||||||
}
|
}
|
||||||
uiConf := dirlist.UiConfig()
|
uiConf := dirlist.UiConfig()
|
||||||
dirlist.spinner = NewSpinner(&uiConf)
|
dirlist.spinner = NewSpinner(&uiConf)
|
||||||
|
@ -87,11 +90,19 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
|
||||||
|
|
||||||
func (dirlist *DirectoryList) Select(name string) {
|
func (dirlist *DirectoryList) Select(name string) {
|
||||||
dirlist.selecting = name
|
dirlist.selecting = name
|
||||||
|
|
||||||
|
close(dirlist.skipSelect)
|
||||||
|
dirlist.skipSelect = make(chan bool)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-time.After(1 * time.Second):
|
||||||
dirlist.worker.PostAction(&types.OpenDirectory{Directory: name},
|
dirlist.worker.PostAction(&types.OpenDirectory{Directory: name},
|
||||||
func(msg types.WorkerMessage) {
|
func(msg types.WorkerMessage) {
|
||||||
switch msg.(type) {
|
switch msg.(type) {
|
||||||
case *types.Error:
|
case *types.Error:
|
||||||
dirlist.selecting = ""
|
dirlist.selecting = ""
|
||||||
|
dirlist.selected = ""
|
||||||
case *types.Done:
|
case *types.Done:
|
||||||
dirlist.selected = dirlist.selecting
|
dirlist.selected = dirlist.selecting
|
||||||
dirlist.filterDirsByFoldersConfig()
|
dirlist.filterDirsByFoldersConfig()
|
||||||
|
@ -113,6 +124,11 @@ func (dirlist *DirectoryList) Select(name string) {
|
||||||
dirlist.Invalidate()
|
dirlist.Invalidate()
|
||||||
})
|
})
|
||||||
dirlist.Invalidate()
|
dirlist.Invalidate()
|
||||||
|
case <-dirlist.skipSelect:
|
||||||
|
dirlist.logger.Println("dirlist: skip", name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dirlist *DirectoryList) Selected() string {
|
func (dirlist *DirectoryList) Selected() string {
|
||||||
|
|
Loading…
Reference in a new issue