commit c78a9bd

delthas  ·  2022-04-20 16:31:19 +0000 UTC
parent cd7f0af
Defer parsing URLs until a buffer is opened at least once

This heavily reduces CPU load on start, so that we only parse the links
of the current buffer hundreds of messages, rather than all of the
hundreds of messages * count of buffers.
1 files changed,  +11, -2
+11, -2
 1@@ -186,6 +186,7 @@ type buffer struct {
 2 	highlights int
 3 	unread     bool
 4 	read       time.Time
 5+	openedOnce bool
 6 
 7 	lines []Line
 8 	topic string
 9@@ -359,7 +360,7 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)
10 	n := len(b.lines)
11 	line.At = line.At.UTC()
12 
13-	if !line.Mergeable {
14+	if !line.Mergeable && current.openedOnce {
15 		line.Body = line.Body.ParseURLs()
16 	}
17 
18@@ -401,7 +402,9 @@ func (bs *BufferList) AddLines(netID, title string, before, after []Line) {
19 				}
20 			} else {
21 				if buf != &b.lines {
22-					line.Body = line.Body.ParseURLs()
23+					if b.openedOnce {
24+						line.Body = line.Body.ParseURLs()
25+					}
26 					line.computeSplitPoints()
27 				}
28 				lines = append(lines, line)
29@@ -686,6 +689,12 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
30 	clearArea(screen, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight+2)
31 
32 	b := bs.cur()
33+	if !b.openedOnce {
34+		b.openedOnce = true
35+		for i := 0; i < len(b.lines); i++ {
36+			b.lines[i].Body = b.lines[i].Body.ParseURLs()
37+		}
38+	}
39 
40 	xTopic := x0
41 	printString(screen, &xTopic, y0, Styled(b.topic, tcell.StyleDefault))