diff options
author | Robin Jarry <robin@jarry.cc> | 2023-07-10 14:42:17 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-07-10 15:16:54 +0200 |
commit | ab3debc1fad99e7a10a530055eed185eb370be79 (patch) | |
tree | b0ea6823269718baa0d984158223b4ddd7713bc8 /widgets | |
parent | 53de61a1ca012b4b63f882a9a55c1cfcc204c5e4 (diff) | |
download | aerc-ab3debc1fad99e7a10a530055eed185eb370be79.tar.gz |
viewer: avoid high cpu usage when selecting part with no filter
When selecting a message part that has no filter configured, aerc uses
very high CPU.
This is due to a recursive UI invalidation. PartViewer.Draw() calls
newNoFilterConfigured which calls ui.Grid.AddChild which in turn calls
ui.Invalidate() which causes the whole UI to be redrawn.
Call newNoFilterConfigured only once when creating a new part viewer
(only when there is no filter command).
Reported-by: Willow Barraco <contact@willowbarraco.fr>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Willow Barraco <contact@willowbarraco.fr>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/msgviewer.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index bb30734d..987d3133 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -528,6 +528,7 @@ type PartViewer struct { source io.Reader term *Terminal grid *ui.Grid + noFilter *ui.Grid uiConfig *config.UIConfig copying int32 @@ -594,6 +595,7 @@ func NewPartViewer( break } } + var noFilter *ui.Grid if filter != nil { path, _ := os.LookupEnv("PATH") for _, dir := range config.SearchDirs { @@ -623,6 +625,8 @@ func NewPartViewer( if term, err = NewTerminal(pager); err != nil { return nil, err } + } else { + noFilter = newNoFilterConfigured(acct.Name(), part) } grid := ui.NewGrid().Rows([]ui.GridSpec{ @@ -645,6 +649,7 @@ func NewPartViewer( part: part, term: term, grid: grid, + noFilter: noFilter, uiConfig: acct.UiConfig(), } @@ -778,13 +783,13 @@ var noFilterConfiguredCommands = [][]string{ {":pipe<space>", "Pipe to shell command"}, } -func newNoFilterConfigured(pv *PartViewer) *ui.Grid { - bindings := config.Binds.MessageView.ForAccount(pv.acctConfig.Name) +func newNoFilterConfigured(account string, part *models.BodyStructure) *ui.Grid { + bindings := config.Binds.MessageView.ForAccount(account) var actions []string configured := noFilterConfiguredCommands - if strings.Contains(strings.ToLower(pv.part.MIMEType), "message") { + if strings.Contains(strings.ToLower(part.MIMEType), "message") { configured = append(configured, []string{ ":eml<Enter>", "View message attachment", }) @@ -818,7 +823,7 @@ func newNoFilterConfigured(pv *PartViewer) *ui.Grid { uiConfig := config.Ui noFilter := fmt.Sprintf(`No filter configured for this mimetype ('%s') -What would you like to do?`, pv.part.FullMIMEType()) +What would you like to do?`, part.FullMIMEType()) grid.AddChild(ui.NewText(noFilter, uiConfig.GetStyle(config.STYLE_TITLE))).At(0, 0) for i, action := range actions { @@ -837,7 +842,7 @@ func (pv *PartViewer) Draw(ctx *ui.Context) { style := pv.uiConfig.GetStyle(config.STYLE_DEFAULT) if pv.filter == nil { ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style) - newNoFilterConfigured(pv).Draw(ctx) + pv.noFilter.Draw(ctx) return } if !pv.fetched { |