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
|
@ -6,6 +6,7 @@ import (
|
|||
"math"
|
||||
"regexp"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/mattn/go-runewidth"
|
||||
|
@ -30,6 +31,7 @@ type DirectoryList struct {
|
|||
scroll int
|
||||
spinner *Spinner
|
||||
worker *types.Worker
|
||||
skipSelect chan bool
|
||||
}
|
||||
|
||||
func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
|
||||
|
@ -41,6 +43,7 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
|
|||
logger: logger,
|
||||
store: lib.NewDirStore(),
|
||||
worker: worker,
|
||||
skipSelect: make(chan bool),
|
||||
}
|
||||
uiConf := dirlist.UiConfig()
|
||||
dirlist.spinner = NewSpinner(&uiConf)
|
||||
|
@ -87,11 +90,19 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
|
|||
|
||||
func (dirlist *DirectoryList) Select(name string) {
|
||||
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},
|
||||
func(msg types.WorkerMessage) {
|
||||
switch msg.(type) {
|
||||
case *types.Error:
|
||||
dirlist.selecting = ""
|
||||
dirlist.selected = ""
|
||||
case *types.Done:
|
||||
dirlist.selected = dirlist.selecting
|
||||
dirlist.filterDirsByFoldersConfig()
|
||||
|
@ -113,6 +124,11 @@ func (dirlist *DirectoryList) Select(name string) {
|
|||
dirlist.Invalidate()
|
||||
})
|
||||
dirlist.Invalidate()
|
||||
case <-dirlist.skipSelect:
|
||||
dirlist.logger.Println("dirlist: skip", name)
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (dirlist *DirectoryList) Selected() string {
|
||||
|
|
Loading…
Reference in New Issue