[MM-44488] Cloud limits: enforcing messages (#20362)
* Add new Job to keep updating the last_accessible_post time * Filter out posts for funcs returning PostList model * Separate methods to get and compute cache * filter pinned posts * For posts with sorted CreateAt order, support a faster form of filtering. * Add inaccessible header for getPost and getPostsByIDs APIs * replace manual binary search with the std. library * in-place filter posts Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Nathaniel Allred <neallred@protonmail.com>
Этот коммит содержится в:
12
api4/post.go
12
api4/post.go
@@ -381,6 +381,7 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// getPost also sets a header to indicate, if post is inaccessible due to the cloud plan's limit.
|
||||
func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequirePostId()
|
||||
if c.Err != nil {
|
||||
@@ -396,6 +397,12 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
post, err := c.App.GetPostIfAuthorized(c.Params.PostId, c.AppContext.Session(), includeDeleted)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
||||
// Post is inaccessible due to cloud plan's limit.
|
||||
if err.Id == "app.post.cloud.get.app_error" {
|
||||
w.Header().Set(model.HeaderHasInaccessiblePosts, "true")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -416,6 +423,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// getPostsByIds also sets a header to indicate, if posts were truncated as per the cloud plan's limit.
|
||||
func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
postIDs := model.ArrayFromJSON(r.Body)
|
||||
|
||||
@@ -429,7 +437,7 @@ func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
postsList, err := c.App.GetPostsByIds(postIDs)
|
||||
postsList, hasInaccessiblePosts, err := c.App.GetPostsByIds(postIDs)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -462,6 +470,8 @@ func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
posts = append(posts, post)
|
||||
}
|
||||
|
||||
w.Header().Set(model.HeaderHasInaccessiblePosts, strconv.FormatBool(hasInaccessiblePosts))
|
||||
|
||||
if err := json.NewEncoder(w).Encode(posts); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user