commit af89d12
delthas
·
2022-04-20 16:45:21 +0000 UTC
parent c78a9bd
Fetch the chat history of the last opened buffer first This will slightly speed up startup time.
1 files changed,
+23,
-8
M
app.go
M
app.go
+23,
-8
1@@ -837,19 +837,34 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
2 bounds.Update(&line)
3 app.messageBounds[boundKey{netID, buffer}] = bounds
4 case irc.HistoryTargetsEvent:
5- for target, last := range ev.Targets {
6- if s.IsChannel(target) {
7+ type target struct {
8+ name string
9+ last time.Time
10+ }
11+ // try to fetch the history of the last opened buffer first
12+ targets := make([]target, 0, len(ev.Targets))
13+ if app.lastNetID == netID {
14+ if last, ok := ev.Targets[app.lastBuffer]; ok {
15+ targets = append(targets, target{app.lastBuffer, last})
16+ delete(ev.Targets, app.lastBuffer)
17+ }
18+ }
19+ for name, last := range ev.Targets {
20+ targets = append(targets, target{name, last})
21+ }
22+ for _, target := range targets {
23+ if s.IsChannel(target.name) {
24 continue
25 }
26- s.MonitorAdd(target)
27- s.ReadGet(target)
28- app.win.AddBuffer(netID, "", target)
29+ s.MonitorAdd(target.name)
30+ s.ReadGet(target.name)
31+ app.win.AddBuffer(netID, "", target.name)
32 // CHATHISTORY BEFORE excludes its bound, so add 1ms
33 // (precision of the time tag) to include that last message.
34- last = last.Add(1 * time.Millisecond)
35- s.NewHistoryRequest(target).
36+ target.last = target.last.Add(1 * time.Millisecond)
37+ s.NewHistoryRequest(target.name).
38 WithLimit(500).
39- Before(last)
40+ Before(target.last)
41 }
42 case irc.HistoryEvent:
43 var linesBefore []ui.Line