Use status cache for checking @here notifications (#5035)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
056be669fc
Коммит
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 hereNotification {
|
||||||
if result := <-Srv.Store.Status().GetOnline(); result.Err != nil {
|
statuses := GetAllStatuses()
|
||||||
l4g.Warn(utils.T("api.post.notification.here.warn"), result.Err)
|
for _, status := range statuses {
|
||||||
return nil
|
if status.UserId == post.UserId {
|
||||||
} else {
|
continue
|
||||||
statuses := result.Data.([]*model.Status)
|
}
|
||||||
for _, status := range statuses {
|
|
||||||
if status.UserId == post.UserId {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
_, profileFound := profileMap[status.UserId]
|
_, profileFound := profileMap[status.UserId]
|
||||||
_, alreadyMentioned := mentionedUserIds[status.UserId]
|
_, alreadyMentioned := mentionedUserIds[status.UserId]
|
||||||
|
|
||||||
if status.Status == model.STATUS_ONLINE && profileFound && !alreadyMentioned {
|
if status.Status == model.STATUS_ONLINE && profileFound && !alreadyMentioned {
|
||||||
mentionedUsersList = append(mentionedUsersList, status.UserId)
|
mentionedUsersList = append(mentionedUsersList, status.UserId)
|
||||||
updateMentionChans = append(updateMentionChans, Srv.Store.Channel().IncrementMentionCount(post.ChannelId, 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) {
|
func getStatusesHttp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
statusMap, err := GetAllStatuses()
|
statusMap := model.StatusMapToInterfaceMap(GetAllStatuses())
|
||||||
if err != nil {
|
|
||||||
c.Err = err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write([]byte(model.StringInterfaceToJson(statusMap)))
|
w.Write([]byte(model.StringInterfaceToJson(statusMap)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStatusesWebSocket(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
|
func getStatusesWebSocket(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
|
||||||
statusMap, err := GetAllStatuses()
|
statusMap := GetAllStatuses()
|
||||||
if err != nil {
|
return model.StatusMapToInterfaceMap(statusMap), nil
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return statusMap, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only returns 300 statuses max
|
func GetAllStatuses() map[string]*model.Status {
|
||||||
func GetAllStatuses() (map[string]interface{}, *model.AppError) {
|
userIds := statusCache.Keys()
|
||||||
if result := <-Srv.Store.Status().GetOnlineAway(); result.Err != nil {
|
statusMap := map[string]*model.Status{}
|
||||||
return nil, result.Err
|
|
||||||
} else {
|
|
||||||
statuses := result.Data.([]*model.Status)
|
|
||||||
|
|
||||||
statusMap := map[string]interface{}{}
|
for _, userId := range userIds {
|
||||||
for _, s := range statuses {
|
if id, ok := userId.(string); !ok {
|
||||||
statusMap[s.UserId] = s.Status
|
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) {
|
func getStatusesByIdsHttp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -268,12 +261,21 @@ func SetStatusAwayIfNeeded(userId string, manual bool) {
|
|||||||
go Publish(event)
|
go Publish(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStatus(userId string) (*model.Status, *model.AppError) {
|
func GetStatusFromCache(userId string) *model.Status {
|
||||||
if result, ok := statusCache.Get(userId); ok {
|
if result, ok := statusCache.Get(userId); ok {
|
||||||
status := result.(*model.Status)
|
status := result.(*model.Status)
|
||||||
statusCopy := &model.Status{}
|
statusCopy := &model.Status{}
|
||||||
*statusCopy = *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 {
|
if result := <-Srv.Store.Status().Get(userId); result.Err != nil {
|
||||||
|
|||||||
@@ -44,3 +44,14 @@ func StatusFromJson(data io.Reader) *Status {
|
|||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user