Improve count updating when marking as read

This commit is contained in:
Peter Stuifzand 2018-07-07 17:14:54 +02:00
parent f1483f4171
commit dfd9b51cc5

View File

@ -714,8 +714,6 @@ func (b *memoryBackend) MarkRead(channel string, uids []string) error {
conn := pool.Get() conn := pool.Get()
defer conn.Close() defer conn.Close()
log.Printf("Marking read for %s %v\n", channel, uids)
itemUIDs := []string{} itemUIDs := []string{}
for _, uid := range uids { for _, uid := range uids {
itemUIDs = append(itemUIDs, "item:"+uid) itemUIDs = append(itemUIDs, "item:"+uid)
@ -725,27 +723,19 @@ func (b *memoryBackend) MarkRead(channel string, uids []string) error {
args := redis.Args{}.Add(channelKey).AddFlat(itemUIDs) args := redis.Args{}.Add(channelKey).AddFlat(itemUIDs)
if _, err := conn.Do("SADD", args...); err != nil { if _, err := conn.Do("SADD", args...); err != nil {
log.Printf("Marking read for channel %s has failed\n", channel) return fmt.Errorf("Marking read for channel %s has failed: %s", channel, err)
return err
} }
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel) zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
args = redis.Args{}.Add(zchannelKey).AddFlat(itemUIDs) args = redis.Args{}.Add(zchannelKey).AddFlat(itemUIDs)
if _, err := conn.Do("ZREM", args...); err != nil { if _, err := conn.Do("ZREM", args...); err != nil {
log.Printf("Marking read for channel %s has failed\n", channel) return fmt.Errorf("Marking read for channel %s has failed: %s", channel, err)
return err
} }
unread, _ := redis.Int(conn.Do("ZCARD", zchannelKey)) err := b.updateChannelUnreadCount(conn, channel)
unread -= len(uids) if err != nil {
return err
if ch, e := b.Channels[channel]; e {
if unread < 0 {
unread = 0
}
ch.Unread = unread
b.Channels[channel] = ch
} }
log.Printf("Marking read success for %s %v\n", channel, itemUIDs) log.Printf("Marking read success for %s %v\n", channel, itemUIDs)