Keep list of read items and skip adding

This commit is contained in:
Peter Stuifzand 2018-04-10 21:14:59 +02:00
parent fbbcd1d3ea
commit c61fe38718
2 changed files with 16 additions and 2 deletions

View File

@ -381,6 +381,13 @@ func (b *memoryBackend) channelAddItem(channel string, item microsub.Item) {
return
}
readChannelKey := fmt.Sprintf("channel:%s:read", channel)
isRead, err := redis.Bool(conn.Do("SISMEMBER", readChannelKey, itemKey))
if isRead {
return
}
added, err := redis.Int64(conn.Do("SADD", channelKey, itemKey))
if err != nil {
log.Printf("error while adding item %s to channel %s for redis: %v\n", itemKey, channelKey, err)

View File

@ -627,14 +627,21 @@ func (b *memoryBackend) MarkRead(channel string, uids []string) {
itemUIDs = append(itemUIDs, "item:"+uid)
}
channelKey := fmt.Sprintf("zchannel:%s:posts", channel)
channelKey := fmt.Sprintf("channel:%s:read", channel)
args := redis.Args{}.Add(channelKey).AddFlat(itemUIDs)
if _, err := conn.Do("SADD", args...); err != nil {
log.Printf("Marking read for channel %s has failed\n", channel)
}
zchannelKey := fmt.Sprintf("zchannel:%s:posts", channel)
args = redis.Args{}.Add(zchannelKey).AddFlat(itemUIDs)
if _, err := conn.Do("ZREM", args...); err != nil {
log.Printf("Marking read for channel %s has failed\n", channel)
}
unread, _ := redis.Int(conn.Do("ZCARD", channelKey))
unread, _ := redis.Int(conn.Do("ZCARD", zchannelKey))
unread -= len(uids)
if ch, e := b.Channels[channel]; e {