Compare commits

...

2 Commits

Author SHA1 Message Date
46c308619e
Only update unread count when it has changed
All checks were successful
continuous-integration/drone/push Build is passing
2019-08-17 22:08:22 +02:00
53b4e748c3
Replace HPUT with HSET
HPUT is not a Redis command
2019-08-17 22:07:53 +02:00
2 changed files with 7 additions and 3 deletions

View File

@ -191,7 +191,7 @@ func (h *hubIncomingBackend) Feeds() ([]Feed, error) {
parts := strings.Split(feedKey, ":") parts := strings.Split(feedKey, ":")
if len(parts) == 2 { if len(parts) == 2 {
feed.ID, _ = strconv.ParseInt(parts[1], 10, 64) feed.ID, _ = strconv.ParseInt(parts[1], 10, 64)
_, err = conn.Do("HPUT", feedKey, "id", feed.ID) _, err = conn.Do("HSET", feedKey, "id", feed.ID)
if err != nil { if err != nil {
log.Printf("could not save id for %s: %v", feedKey, err) log.Printf("could not save id for %s: %v", feedKey, err)
} }
@ -208,7 +208,7 @@ func (h *hubIncomingBackend) Feeds() ([]Feed, error) {
} }
feed.Callback = fmt.Sprintf("%s/incoming/%d", h.baseURL, feed.ID) feed.Callback = fmt.Sprintf("%s/incoming/%d", h.baseURL, feed.ID)
_, err = conn.Do("HPUT", feedKey, "callback", feed.Callback) _, err = conn.Do("HSET", feedKey, "callback", feed.Callback)
if err != nil { if err != nil {
log.Printf("could not save id for %s: %v", feedKey, err) log.Printf("could not save id for %s: %v", feedKey, err)
} }

View File

@ -661,10 +661,14 @@ func (b *memoryBackend) updateChannelUnreadCount(channel string) error {
return err return err
} }
defer b.save() defer b.save()
currentCount := c.Unread.UnreadCount
c.Unread = microsub.Unread{Type: microsub.UnreadCount, UnreadCount: unread} c.Unread = microsub.Unread{Type: microsub.UnreadCount, UnreadCount: unread}
// Sent message to Server-Sent-Events // Sent message to Server-Sent-Events
if currentCount != unread {
b.broker.Notifier <- sse.Message{Event: "new item in channel", Object: c} b.broker.Notifier <- sse.Message{Event: "new item in channel", Object: c}
}
b.lock.Lock() b.lock.Lock()
b.Channels[channel] = c b.Channels[channel] = c