mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Use status cache for checking @here notifications (#5035)
This commit is contained in:
committed by
Harrison Healey
parent
056be669fc
commit
4101b28de5
25
api/post.go
25
api/post.go
@@ -787,23 +787,18 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
||||
}
|
||||
|
||||
if hereNotification {
|
||||
if result := <-Srv.Store.Status().GetOnline(); result.Err != nil {
|
||||
l4g.Warn(utils.T("api.post.notification.here.warn"), result.Err)
|
||||
return nil
|
||||
} else {
|
||||
statuses := result.Data.([]*model.Status)
|
||||
for _, status := range statuses {
|
||||
if status.UserId == post.UserId {
|
||||
continue
|
||||
}
|
||||
statuses := GetAllStatuses()
|
||||
for _, status := range statuses {
|
||||
if status.UserId == post.UserId {
|
||||
continue
|
||||
}
|
||||
|
||||
_, profileFound := profileMap[status.UserId]
|
||||
_, alreadyMentioned := mentionedUserIds[status.UserId]
|
||||
_, profileFound := profileMap[status.UserId]
|
||||
_, alreadyMentioned := mentionedUserIds[status.UserId]
|
||||
|
||||
if status.Status == model.STATUS_ONLINE && profileFound && !alreadyMentioned {
|
||||
mentionedUsersList = append(mentionedUsersList, status.UserId)
|
||||
updateMentionChans = append(updateMentionChans, Srv.Store.Channel().IncrementMentionCount(post.ChannelId, status.UserId))
|
||||
}
|
||||
if status.Status == model.STATUS_ONLINE && profileFound && !alreadyMentioned {
|
||||
mentionedUsersList = append(mentionedUsersList, status.UserId)
|
||||
updateMentionChans = append(updateMentionChans, Srv.Store.Channel().IncrementMentionCount(post.ChannelId, status.UserId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,38 +42,31 @@ func InitStatus() {
|
||||
}
|
||||
|
||||
func getStatusesHttp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
statusMap, err := GetAllStatuses()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
statusMap := model.StatusMapToInterfaceMap(GetAllStatuses())
|
||||
w.Write([]byte(model.StringInterfaceToJson(statusMap)))
|
||||
}
|
||||
|
||||
func getStatusesWebSocket(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
|
||||
statusMap, err := GetAllStatuses()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return statusMap, nil
|
||||
statusMap := GetAllStatuses()
|
||||
return model.StatusMapToInterfaceMap(statusMap), nil
|
||||
}
|
||||
|
||||
// Only returns 300 statuses max
|
||||
func GetAllStatuses() (map[string]interface{}, *model.AppError) {
|
||||
if result := <-Srv.Store.Status().GetOnlineAway(); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
statuses := result.Data.([]*model.Status)
|
||||
func GetAllStatuses() map[string]*model.Status {
|
||||
userIds := statusCache.Keys()
|
||||
statusMap := map[string]*model.Status{}
|
||||
|
||||
statusMap := map[string]interface{}{}
|
||||
for _, s := range statuses {
|
||||
statusMap[s.UserId] = s.Status
|
||||
for _, userId := range userIds {
|
||||
if id, ok := userId.(string); !ok {
|
||||
continue
|
||||
} else {
|
||||
status := GetStatusFromCache(id)
|
||||
if status != nil {
|
||||
statusMap[id] = status
|
||||
}
|
||||
}
|
||||
|
||||
return statusMap, nil
|
||||
}
|
||||
|
||||
return statusMap
|
||||
}
|
||||
|
||||
func getStatusesByIdsHttp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -268,12 +261,21 @@ func SetStatusAwayIfNeeded(userId string, manual bool) {
|
||||
go Publish(event)
|
||||
}
|
||||
|
||||
func GetStatus(userId string) (*model.Status, *model.AppError) {
|
||||
func GetStatusFromCache(userId string) *model.Status {
|
||||
if result, ok := statusCache.Get(userId); ok {
|
||||
status := result.(*model.Status)
|
||||
statusCopy := &model.Status{}
|
||||
*statusCopy = *status
|
||||
return statusCopy, nil
|
||||
return statusCopy
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetStatus(userId string) (*model.Status, *model.AppError) {
|
||||
status := GetStatusFromCache(userId)
|
||||
if status != nil {
|
||||
return status, nil
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Status().Get(userId); result.Err != nil {
|
||||
|
||||
@@ -44,3 +44,14 @@ func StatusFromJson(data io.Reader) *Status {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func StatusMapToInterfaceMap(statusMap map[string]*Status) map[string]interface{} {
|
||||
interfaceMap := map[string]interface{}{}
|
||||
for _, s := range statusMap {
|
||||
// Omitted statues mean offline
|
||||
if s.Status != STATUS_OFFLINE {
|
||||
interfaceMap[s.UserId] = s.Status
|
||||
}
|
||||
}
|
||||
return interfaceMap
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user