perf: batch group unread fanout
This commit is contained in:
+24
-3
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/tinode/chat/server/logs"
|
||||
immetrics "github.com/tinode/chat/server/metrics"
|
||||
"github.com/tinode/chat/server/store"
|
||||
"github.com/tinode/chat/server/store/types"
|
||||
)
|
||||
@@ -466,12 +467,26 @@ func (t *Topic) presSubsOffline(what string, params *presParams,
|
||||
if offlineOnly {
|
||||
skipTopic = t.name
|
||||
}
|
||||
if t.cat == types.TopicCatGrp && offlineOnly && what == "msg" && store.RealtimeFanoutEnabled() {
|
||||
recipients := make([]realtimeGroupUnreadRecipient, 0, len(t.perUser))
|
||||
for uid, pud := range t.perUser {
|
||||
if pud.deleted || !presOfflineFilter(pud.modeGiven&pud.modeWant, what, filterSource) {
|
||||
continue
|
||||
}
|
||||
recipients = append(recipients, realtimeGroupUnreadRecipient{
|
||||
User: uid.UserId(),
|
||||
Source: t.original(uid),
|
||||
})
|
||||
}
|
||||
if publishRealtimeGroupUnread(t.tenantID, t.name, params.actor, params.seqID, recipients) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for uid, pud := range t.perUser {
|
||||
if pud.deleted || !presOfflineFilter(pud.modeGiven&pud.modeWant, what, filterSource) {
|
||||
continue
|
||||
}
|
||||
|
||||
user := uid.UserId()
|
||||
actor := params.actor
|
||||
target := params.target
|
||||
@@ -693,10 +708,16 @@ func presSingleUserOfflineOffline(tenantID types.TenantID, uid types.Uid, origin
|
||||
}
|
||||
|
||||
func routeUserServerMessage(uid types.Uid, msg *ServerComMessage) {
|
||||
if msg == nil || uid.IsZero() {
|
||||
if msg == nil || uid.IsZero() || globals.hub == nil {
|
||||
return
|
||||
}
|
||||
globals.hub.routeSrv <- msg
|
||||
select {
|
||||
case globals.hub.routeSrv <- msg:
|
||||
immetrics.ObserveInternalQueueEnqueue("hub_route_server", len(globals.hub.routeSrv), cap(globals.hub.routeSrv), true)
|
||||
default:
|
||||
immetrics.ObserveInternalQueueEnqueue("hub_route_server", len(globals.hub.routeSrv), cap(globals.hub.routeSrv), false)
|
||||
logs.Err.Printf("route user message: hub routeSrv queue full, user=%s", uid.UserId())
|
||||
}
|
||||
publishRealtimeUserMessage(uid, msg)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user