~taiite/senpai

c78a9bd9fa6294b8b86e645d77c5f8fd8384fac9 — delthas a month ago 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 insertions(+), 2 deletions(-)

M ui/buffers.go
M ui/buffers.go => ui/buffers.go +11 -2
@@ 186,6 186,7 @@ type buffer struct {
	highlights int
	unread     bool
	read       time.Time
	openedOnce bool

	lines []Line
	topic string


@@ 359,7 360,7 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line)
	n := len(b.lines)
	line.At = line.At.UTC()

	if !line.Mergeable {
	if !line.Mergeable && current.openedOnce {
		line.Body = line.Body.ParseURLs()
	}



@@ 401,7 402,9 @@ func (bs *BufferList) AddLines(netID, title string, before, after []Line) {
				}
			} else {
				if buf != &b.lines {
					line.Body = line.Body.ParseURLs()
					if b.openedOnce {
						line.Body = line.Body.ParseURLs()
					}
					line.computeSplitPoints()
				}
				lines = append(lines, line)


@@ 686,6 689,12 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int
	clearArea(screen, x0, y0, bs.tlInnerWidth+nickColWidth+9, bs.tlHeight+2)

	b := bs.cur()
	if !b.openedOnce {
		b.openedOnce = true
		for i := 0; i < len(b.lines); i++ {
			b.lines[i].Body = b.lines[i].Body.ParseURLs()
		}
	}

	xTopic := x0
	printString(screen, &xTopic, y0, Styled(b.topic, tcell.StyleDefault))