diff --git a/downstream.go b/downstream.go index 755beb2..09b34c7 100644 --- a/downstream.go +++ b/downstream.go @@ -864,17 +864,11 @@ func (dc *downstreamConn) sendNetworkHistory(net *network) { continue } - seq, ok := history.offlineClients[dc.clientName] + seq, ok := history.clients[dc.clientName] if !ok { continue } - delete(history.offlineClients, dc.clientName) - - // If all clients have received history, no need to keep the - // ring buffer around - if len(history.offlineClients) == 0 { - delete(net.history, target) - } + history.clients[dc.clientName] = history.ring.Cur() consumer := history.ring.NewConsumer(seq) diff --git a/upstream.go b/upstream.go index 1f9cacf..97fb9ec 100644 --- a/upstream.go +++ b/upstream.go @@ -1635,33 +1635,34 @@ func (uc *upstreamConn) appendHistory(entity string, msg *irc.Message) { detached = ch.Detached } - // If no client is offline, no need to append the message to the buffer - if len(uc.network.offlineClients) == 0 && !detached { - return - } - history, ok := uc.network.history[entity] if !ok { history = &networkHistory{ - offlineClients: make(map[string]uint64), - ring: NewRing(uc.srv.RingCap), + clients: make(map[string]uint64), + ring: NewRing(uc.srv.RingCap), } uc.network.history[entity] = history for clientName, _ := range uc.network.offlineClients { - history.offlineClients[clientName] = 0 + history.clients[clientName] = 0 } if detached { // If the channel is detached, online clients act as offline // clients too uc.forEachDownstream(func(dc *downstreamConn) { - history.offlineClients[dc.clientName] = 0 + history.clients[dc.clientName] = 0 }) } } history.ring.Produce(msg) + + if !detached { + uc.forEachDownstream(func(dc *downstreamConn) { + history.clients[dc.clientName] = history.ring.Cur() + }) + } } // produce appends a message to the logs, adds it to the history and forwards diff --git a/user.go b/user.go index 1febc43..4cae173 100644 --- a/user.go +++ b/user.go @@ -51,8 +51,8 @@ type eventDownstreamDisconnected struct { type eventStop struct{} type networkHistory struct { - offlineClients map[string]uint64 // indexed by client name - ring *Ring // can be nil if there are no offline clients + clients map[string]uint64 // indexed by client name + ring *Ring // can be nil if there are no offline clients } type network struct { @@ -193,9 +193,6 @@ func (net *network) createUpdateChannel(ch *Channel) error { net.user.srv.Logger.Printf("network %q: detaching channel %q", net.GetName(), ch.Name) net.forEachDownstream(func(dc *downstreamConn) { net.offlineClients[dc.clientName] = struct{}{} - if history != nil { - history.offlineClients[dc.clientName] = history.ring.Cur() - } dc.SendMessage(&irc.Message{ Prefix: dc.prefix(), @@ -423,12 +420,6 @@ func (u *user) run() { } net.offlineClients[dc.clientName] = struct{}{} - for target, history := range net.history { - if ch, ok := net.channels[target]; ok && ch.Detached { - continue - } - history.offlineClients[dc.clientName] = history.ring.Cur() - } }) u.forEachUpstream(func(uc *upstreamConn) {