Use updateChannelInRedis with uid and prio

This commit is contained in:
Peter Stuifzand 2018-10-03 19:03:33 +02:00
parent beba0e5120
commit 7252675aba
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -41,6 +41,8 @@ import (
"willnorris.com/go/microformats" "willnorris.com/go/microformats"
) )
const DefaultPrio = 9999999
type memoryBackend struct { type memoryBackend struct {
hubIncomingBackend hubIncomingBackend
@ -117,14 +119,14 @@ func (b *memoryBackend) refreshChannels() {
conn.Do("DEL", "channels") conn.Do("DEL", "channels")
conn.Do("SADD", "channels", "notifications") updateChannelInRedis(conn, "notifications", 1)
conn.Do("SETNX", "channel_sortorder_notifications", 1)
b.lock.RLock() b.lock.RLock()
for uid, channel := range b.Channels { for uid, channel := range b.Channels {
log.Printf("loading channel %s - %s\n", uid, channel.Name) log.Printf("loading channel %s - %s\n", uid, channel.Name)
updateChannelInRedis(conn, channel) updateChannelInRedis(conn, channel.UID, DefaultPrio)
} }
b.lock.RUnlock() b.lock.RUnlock()
} }
@ -221,10 +223,9 @@ func (b *memoryBackend) setChannel(channel microsub.Channel) {
b.NextUid++ b.NextUid++
} }
func updateChannelInRedis(conn redis.Conn, channel microsub.Channel) { func updateChannelInRedis(conn redis.Conn, uid string, prio int) {
uid := channel.UID
conn.Do("SADD", "channels", uid) conn.Do("SADD", "channels", uid)
conn.Do("SETNX", "channel_sortorder_"+uid, 99999) conn.Do("SETNX", "channel_sortorder_"+uid, prio)
} }
// ChannelsCreate creates a channels // ChannelsCreate creates a channels
@ -237,7 +238,7 @@ func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
conn := pool.Get() conn := pool.Get()
defer conn.Close() defer conn.Close()
updateChannelInRedis(conn, channel) updateChannelInRedis(conn, channel.UID, DefaultPrio)
return channel, nil return channel, nil
} }