[MM-61462] Fix errcheck issues in server/channels/app/post.go (#29205)

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
Rohan Sharma
2024-11-20 19:13:48 +05:30
коммит произвёл GitHub
родитель 82bd3b6df1
Коммит 5de425c298
3 изменённых файлов: 19 добавлений и 6 удалений

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

@@ -119,7 +119,6 @@ issues:
channels/app/plugin_install.go|\ channels/app/plugin_install.go|\
channels/app/plugin_signature_test.go|\ channels/app/plugin_signature_test.go|\
channels/app/plugin_test.go|\ channels/app/plugin_test.go|\
channels/app/post.go|\
channels/app/post_helpers_test.go|\ channels/app/post_helpers_test.go|\
channels/app/post_test.go|\ channels/app/post_test.go|\
channels/app/security_update_check.go|\ channels/app/security_update_check.go|\

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

@@ -145,7 +145,9 @@ func (a *App) deduplicateCreatePost(rctx request.CTX, post *model.Post) (foundPo
var postID string var postID string
nErr := a.Srv().seenPendingPostIdsCache.Get(post.PendingPostId, &postID) nErr := a.Srv().seenPendingPostIdsCache.Get(post.PendingPostId, &postID)
if nErr == cache.ErrKeyNotFound { if nErr == cache.ErrKeyNotFound {
a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, PendingPostIDsCacheTTL) if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, unknownPostId, PendingPostIDsCacheTTL); appErr != nil {
return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
}
return nil, nil return nil, nil
} }
@@ -193,11 +195,15 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
} }
if err != nil { if err != nil {
a.Srv().seenPendingPostIdsCache.Remove(post.PendingPostId) if appErr := a.Srv().seenPendingPostIdsCache.Remove(post.PendingPostId); appErr != nil {
err = model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
}
return return
} }
a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, savedPost.Id, PendingPostIDsCacheTTL) if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, savedPost.Id, PendingPostIDsCacheTTL); appErr != nil {
err = model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
}
}() }()
// Validate recipients counts in case it's not DM // Validate recipients counts in case it's not DM
@@ -361,7 +367,9 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
// Update the mapping from pending post id to the actual post id, for any clients that // Update the mapping from pending post id to the actual post id, for any clients that
// might be duplicating requests. // might be duplicating requests.
a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PendingPostIDsCacheTTL) if appErr := a.Srv().seenPendingPostIdsCache.SetWithExpiry(post.PendingPostId, rpost.Id, PendingPostIDsCacheTTL); appErr != nil {
return nil, model.NewAppError("CreatePost", "api.post.deduplicate_create_post.cache_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
}
if a.Metrics() != nil { if a.Metrics() != nil {
a.Metrics().IncrementPostCreate() a.Metrics().IncrementPostCreate()
@@ -1536,7 +1544,9 @@ func (a *App) searchPostsInTeam(teamID string, userID string, paramsList []*mode
posts.SortByCreateAt() posts.SortByCreateAt()
a.filterInaccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: true}) if appErr := a.filterInaccessiblePosts(posts, filterPostOptions{assumeSortedCreatedAt: true}); appErr != nil {
return nil, appErr
}
return posts, nil return posts, nil
} }

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

@@ -2520,6 +2520,10 @@
"id": "api.post.create_webhook_post.creating.app_error", "id": "api.post.create_webhook_post.creating.app_error",
"translation": "Error creating post." "translation": "Error creating post."
}, },
{
"id": "api.post.deduplicate_create_post.cache_error",
"translation": "Failed to cache post after deduplicating a client repeating the same request."
},
{ {
"id": "api.post.deduplicate_create_post.failed_to_get", "id": "api.post.deduplicate_create_post.failed_to_get",
"translation": "Failed to fetch original post after deduplicating a client repeating the same request." "translation": "Failed to fetch original post after deduplicating a client repeating the same request."