From af89d12a6c1dbb4e428ddeb47b3f892b4c046e10 Mon Sep 17 00:00:00 2001 From: delthas Date: Wed, 20 Apr 2022 18:45:21 +0200 Subject: Fetch the chat history of the last opened buffer first This will slightly speed up startup time. --- app.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/app.go b/app.go index 1bea770..b044a06 100644 --- a/app.go +++ b/app.go @@ -837,19 +837,34 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) { bounds.Update(&line) app.messageBounds[boundKey{netID, buffer}] = bounds case irc.HistoryTargetsEvent: - for target, last := range ev.Targets { - if s.IsChannel(target) { + type target struct { + name string + last time.Time + } + // try to fetch the history of the last opened buffer first + targets := make([]target, 0, len(ev.Targets)) + if app.lastNetID == netID { + if last, ok := ev.Targets[app.lastBuffer]; ok { + targets = append(targets, target{app.lastBuffer, last}) + delete(ev.Targets, app.lastBuffer) + } + } + for name, last := range ev.Targets { + targets = append(targets, target{name, last}) + } + for _, target := range targets { + if s.IsChannel(target.name) { continue } - s.MonitorAdd(target) - s.ReadGet(target) - app.win.AddBuffer(netID, "", target) + s.MonitorAdd(target.name) + s.ReadGet(target.name) + app.win.AddBuffer(netID, "", target.name) // CHATHISTORY BEFORE excludes its bound, so add 1ms // (precision of the time tag) to include that last message. - last = last.Add(1 * time.Millisecond) - s.NewHistoryRequest(target). + target.last = target.last.Add(1 * time.Millisecond) + s.NewHistoryRequest(target.name). WithLimit(500). - Before(last) + Before(target.last) } case irc.HistoryEvent: var linesBefore []ui.Line -- cgit v1.2.3