1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-29 07:45:33 +00:00

Speed up subscription janitor to 1min

This commit is contained in:
Kane York 2015-11-09 14:44:33 -08:00
parent 29eb07f58c
commit 377afb7a6b
3 changed files with 13 additions and 8 deletions

View file

@ -52,7 +52,7 @@ func commandLineConsole() {
if target == "_ALL" { if target == "_ALL" {
count = server.PublishToAll(msg) count = server.PublishToAll(msg)
} else { } else {
count = server.PublishToChat(target, msg) count = server.PublishToChannel(target, msg)
} }
return fmt.Sprintf("Published to %d clients", count), nil return fmt.Sprintf("Published to %d clients", count), nil
}) })

View file

@ -77,6 +77,7 @@ func HandleHello(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (r
} }
SubscribeGlobal(client) SubscribeGlobal(client)
SubscribeDefaults(client)
return ClientMessage{ return ClientMessage{
Arguments: client.ClientID.String(), Arguments: client.ClientID.String(),

View file

@ -18,18 +18,22 @@ var ChatSubscriptionInfo map[string]*SubscriberList = make(map[string]*Subscribe
var ChatSubscriptionLock sync.RWMutex var ChatSubscriptionLock sync.RWMutex
var GlobalSubscriptionInfo SubscriberList var GlobalSubscriptionInfo SubscriberList
func SubscribeGlobal(client *ClientInfo) {
GlobalSubscriptionInfo.Lock()
AddToSliceC(&GlobalSubscriptionInfo.Members, client.MessageChannel)
GlobalSubscriptionInfo.Unlock()
}
func SubscribeChannel(client *ClientInfo, channelName string) { func SubscribeChannel(client *ClientInfo, channelName string) {
ChatSubscriptionLock.RLock() ChatSubscriptionLock.RLock()
_subscribeWhileRlocked(channelName, client.MessageChannel) _subscribeWhileRlocked(channelName, client.MessageChannel)
ChatSubscriptionLock.RUnlock() ChatSubscriptionLock.RUnlock()
} }
func SubscribeDefaults(client *ClientInfo) {
}
func SubscribeGlobal(client *ClientInfo) {
GlobalSubscriptionInfo.Lock()
AddToSliceC(&GlobalSubscriptionInfo.Members, client.MessageChannel)
GlobalSubscriptionInfo.Unlock()
}
func PublishToChannel(channel string, msg ClientMessage) (count int) { func PublishToChannel(channel string, msg ClientMessage) (count int) {
ChatSubscriptionLock.RLock() ChatSubscriptionLock.RLock()
list := ChatSubscriptionInfo[channel] list := ChatSubscriptionInfo[channel]
@ -130,7 +134,7 @@ func unsubscribeAllClients() {
ChatSubscriptionLock.Unlock() ChatSubscriptionLock.Unlock()
} }
const ReapingDelay = 20 * time.Minute const ReapingDelay = 1 * time.Minute
// Checks ChatSubscriptionInfo for entries with no subscribers every ReapingDelay. // Checks ChatSubscriptionInfo for entries with no subscribers every ReapingDelay.
// Started from SetupServer(). // Started from SetupServer().