summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-01-10 11:38:03 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-01-10 11:38:03 -0500
commit4101b28de58ab8c2e821cda5f8e7bc8e836d7bb8 (patch)
tree08487ad295df115bcbd07b42f85acd63ca65b986 /api
parent056be669fc99eaa23905fb79ce970ac87302bd69 (diff)
downloadchat-4101b28de58ab8c2e821cda5f8e7bc8e836d7bb8.tar.gz
chat-4101b28de58ab8c2e821cda5f8e7bc8e836d7bb8.tar.bz2
chat-4101b28de58ab8c2e821cda5f8e7bc8e836d7bb8.zip
Use status cache for checking @here notifications (#5035)
Diffstat (limited to 'api')
-rw-r--r--api/post.go25
-rw-r--r--api/status.go52
2 files changed, 37 insertions, 40 deletions
diff --git a/api/post.go b/api/post.go
index 8d6fa0b02..45ead08e0 100644
--- a/api/post.go
+++ b/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))
}
}
}
diff --git a/api/status.go b/api/status.go
index 99d5bc417..909ab50ec 100644
--- a/api/status.go
+++ b/api/status.go
@@ -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 {