[MM-13820] Optimize flagged post handling in preferences and web handler (#10135)

* Optimize flagged post handling in preferences and web handler
Этот коммит содержится в:
Daniel Schalla
2019-01-26 20:02:46 +01:00
коммит произвёл GitHub
родитель 94e45c3466
Коммит b890f8d007
3 изменённых файлов: 110 добавлений и 4 удалений

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

@@ -195,12 +195,37 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
posts, err = c.App.GetFlaggedPosts(c.Params.UserId, c.Params.Page, c.Params.PerPage)
}
pl := model.NewPostList()
channelReadPermission := make(map[string]bool)
for _, post := range posts.Posts {
allowed, ok := channelReadPermission[post.ChannelId]
if !ok {
allowed = false
if c.App.SessionHasPermissionToChannel(c.App.Session, post.ChannelId, model.PERMISSION_READ_CHANNEL) {
allowed = true
}
channelReadPermission[post.ChannelId] = allowed
}
if !allowed {
continue
}
pl.AddPost(post)
pl.AddOrder(post.Id)
}
if err != nil {
c.Err = err
return
}
w.Write([]byte(c.App.PreparePostListForClient(posts).ToJson()))
w.Write([]byte(c.App.PreparePostListForClient(pl).ToJson()))
}
func getPost(c *Context, w http.ResponseWriter, r *http.Request) {