[MM-16561] Store: Migrate UserStore.GetUnreadCount to sync as default #11395 (#11409)

Этот коммит содержится в:
Jesper Hansen
2019-06-26 16:48:20 +02:00
коммит произвёл Miguel de la Cruz
родитель 9bab407f26
Коммит 2193e43aac
5 изменённых файлов: 33 добавлений и 26 удалений

Просмотреть файл

@@ -1187,20 +1187,21 @@ func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) store.StoreChannel
})
}
func (us SqlUserStore) GetUnreadCount(userId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if count, err := us.GetReplica().SelectInt(`
func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
query := `
SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END)
FROM Channels c
INNER JOIN ChannelMembers cm
ON cm.ChannelId = c.Id
AND cm.UserId = :UserId
AND c.DeleteAt = 0`, map[string]interface{}{"UserId": userId}); err != nil {
result.Err = model.NewAppError("SqlUserStore.GetMentionCount", "store.sql_user.get_unread_count.app_error", nil, err.Error(), http.StatusInternalServerError)
} else {
result.Data = count
}
})
ON cm.ChannelId = c.Id
AND cm.UserId = :UserId
AND c.DeleteAt = 0
`
count, err := us.GetReplica().SelectInt(query, map[string]interface{}{"UserId": userId})
if err != nil {
return count, model.NewAppError("SqlUserStore.GetMentionCount", "store.sql_user.get_unread_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
}
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) store.StoreChannel {