MM-58038: Use context to call master for DeletePost (#27098)
Calling app.DeletePost immediately after creating a post is susceptible to replica lag because we were calling the replica to check for the post. We fix this by passing a context to always query master. https://mattermost.atlassian.net/browse/MM-58038 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
09c0eb7e7a
Коммит
6f3327ce0f
@@ -820,7 +820,7 @@ type AppIface interface {
|
||||
GetSidebarCategoriesForTeamForUser(c request.CTX, userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
|
||||
GetSidebarCategory(c request.CTX, categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
|
||||
GetSidebarCategoryOrder(c request.CTX, userID, teamID string) ([]string, *model.AppError)
|
||||
GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError)
|
||||
GetSinglePost(rctx request.CTX, postID string, includeDeleted bool) (*model.Post, *model.AppError)
|
||||
GetSiteURL() string
|
||||
GetStatus(userID string) (*model.Status, *model.AppError)
|
||||
GetStatusFromCache(userID string) *model.Status
|
||||
@@ -830,7 +830,7 @@ type AppIface interface {
|
||||
GetTeamByName(name string) (*model.Team, *model.AppError)
|
||||
GetTeamIcon(team *model.Team) ([]byte, *model.AppError)
|
||||
GetTeamIdFromQuery(rctx request.CTX, query url.Values) (string, *model.AppError)
|
||||
GetTeamMember(c request.CTX, teamID, userID string) (*model.TeamMember, *model.AppError)
|
||||
GetTeamMember(rctx request.CTX, teamID, userID string) (*model.TeamMember, *model.AppError)
|
||||
GetTeamMembers(teamID string, offset int, limit int, teamMembersGetOptions *model.TeamMembersGetOptions) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersByIds(teamID string, userIDs []string, restrictions *model.ViewUsersRestrictions) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersForUser(c request.CTX, userID string, excludeTeamID string, includeDeleted bool) ([]*model.TeamMember, *model.AppError)
|
||||
|
||||
@@ -2700,7 +2700,7 @@ func (a *App) MarkChannelAsUnreadFromPost(c request.CTX, postID string, userID s
|
||||
if !collapsedThreadsSupported || !a.IsCRTEnabledForUser(c, userID) {
|
||||
return a.markChannelAsUnreadFromPostCRTUnsupported(c, postID, userID)
|
||||
}
|
||||
post, err := a.GetSinglePost(postID, false)
|
||||
post, err := a.GetSinglePost(c, postID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2727,7 +2727,7 @@ func (a *App) MarkChannelAsUnreadFromPost(c request.CTX, postID string, userID s
|
||||
}
|
||||
|
||||
func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID string, userID string) (*model.ChannelUnreadAt, *model.AppError) {
|
||||
post, appErr := a.GetSinglePost(postID, false)
|
||||
post, appErr := a.GetSinglePost(c, postID, false)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
@@ -2766,7 +2766,7 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st
|
||||
// If there are replies with mentions below the marked reply in the thread, then sum the mentions for the threads mention badge.
|
||||
// In CRT Unsupported Client: Channel is marked as unread and new messages line inserted above the marked post.
|
||||
// Badge on channel sums mentions in all posts (root & replies) including and below the post that was marked unread.
|
||||
rootPost, appErr := a.GetSinglePost(post.RootId, false)
|
||||
rootPost, appErr := a.GetSinglePost(c, post.RootId, false)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
|
||||
// Start all queries here for parallel execution
|
||||
pchan := make(chan store.StoreResult[*model.Post], 1)
|
||||
go func() {
|
||||
post, err := a.Srv().Store().Post().GetSingle(postID, false)
|
||||
post, err := a.Srv().Store().Post().GetSingle(c, postID, false)
|
||||
pchan <- store.StoreResult[*model.Post]{Data: post, NErr: err}
|
||||
close(pchan)
|
||||
}()
|
||||
|
||||
@@ -530,7 +530,7 @@ func TestPostActionProps(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
assert.True(t, len(clientTriggerId) == 26)
|
||||
|
||||
newPost, nErr := th.App.Srv().Store().Post().GetSingle(post.Id, false)
|
||||
newPost, nErr := th.App.Srv().Store().Post().GetSingle(th.Context, post.Id, false)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
assert.True(t, newPost.IsPinned)
|
||||
|
||||
@@ -9818,7 +9818,7 @@ func (a *OpenTracingAppLayer) GetSidebarCategoryOrder(c request.CTX, userID stri
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetSinglePost(rctx request.CTX, postID string, includeDeleted bool) (*model.Post, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSinglePost")
|
||||
|
||||
@@ -9830,7 +9830,7 @@ func (a *OpenTracingAppLayer) GetSinglePost(postID string, includeDeleted bool)
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetSinglePost(postID, includeDeleted)
|
||||
resultVar0, resultVar1 := a.app.GetSinglePost(rctx, postID, includeDeleted)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -10089,7 +10089,7 @@ func (a *OpenTracingAppLayer) GetTeamIdFromQuery(rctx request.CTX, query url.Val
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetTeamMember(c request.CTX, teamID string, userID string) (*model.TeamMember, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetTeamMember(rctx request.CTX, teamID string, userID string) (*model.TeamMember, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTeamMember")
|
||||
|
||||
@@ -10101,7 +10101,7 @@ func (a *OpenTracingAppLayer) GetTeamMember(c request.CTX, teamID string, userID
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetTeamMember(c, teamID, userID)
|
||||
resultVar0, resultVar1 := a.app.GetTeamMember(rctx, teamID, userID)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
|
||||
@@ -704,7 +704,7 @@ func (api *PluginAPI) GetPostThread(postID string) (*model.PostList, *model.AppE
|
||||
}
|
||||
|
||||
func (api *PluginAPI) GetPost(postID string) (*model.Post, *model.AppError) {
|
||||
post, appErr := api.app.GetSinglePost(postID, false)
|
||||
post, appErr := api.app.GetSinglePost(api.ctx, postID, false)
|
||||
if post != nil {
|
||||
post = post.ForPlugin()
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "message", post.Message)
|
||||
retrievedPost, errSingle := th.App.Srv().Store().Post().GetSingle(post.Id, false)
|
||||
retrievedPost, errSingle := th.App.Srv().Store().Post().GetSingle(th.Context, post.Id, false)
|
||||
require.NoError(t, errSingle)
|
||||
assert.Equal(t, "message", retrievedPost.Message)
|
||||
})
|
||||
@@ -229,7 +229,7 @@ func TestHookMessageWillBePosted(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "message_fromplugin", post.Message)
|
||||
retrievedPost, errSingle := th.App.Srv().Store().Post().GetSingle(post.Id, false)
|
||||
retrievedPost, errSingle := th.App.Srv().Store().Post().GetSingle(th.Context, post.Id, false)
|
||||
require.NoError(t, errSingle)
|
||||
assert.Equal(t, "message_fromplugin", retrievedPost.Message)
|
||||
})
|
||||
@@ -1606,7 +1606,7 @@ func TestHookMessagesWillBeConsumed(t *testing.T) {
|
||||
_, err := th.App.CreatePost(th.Context, newPost, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err := th.App.GetSinglePost(newPost.Id, true)
|
||||
post, err := th.App.GetSinglePost(th.Context, newPost.Id, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "message", post.Message)
|
||||
})
|
||||
@@ -1629,7 +1629,7 @@ func TestHookMessagesWillBeConsumed(t *testing.T) {
|
||||
_, err := th.App.CreatePost(th.Context, newPost, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err := th.App.GetSinglePost(newPost.Id, true)
|
||||
post, err := th.App.GetSinglePost(th.Context, newPost.Id, true)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "mwbc_plugin:message", post.Message)
|
||||
})
|
||||
|
||||
@@ -130,7 +130,7 @@ func (a *App) deduplicateCreatePost(rctx request.CTX, post *model.Post) (foundPo
|
||||
|
||||
// If the other thread finished creating the post, return the created post back to the
|
||||
// client, making the API call feel idempotent.
|
||||
actualPost, err := a.GetSinglePost(postID, false)
|
||||
actualPost, err := a.GetSinglePost(rctx, postID, false)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.failed_to_get", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -795,7 +795,7 @@ func (a *App) publishWebsocketEventForPermalinkPost(c request.CTX, post *model.P
|
||||
return false, nil
|
||||
}
|
||||
|
||||
previewedPost, err := a.GetSinglePost(previewedPostID, false)
|
||||
previewedPost, err := a.GetSinglePost(c, previewedPostID, false)
|
||||
if err != nil {
|
||||
if err.StatusCode == http.StatusNotFound {
|
||||
a.CountNotificationReason(model.NotificationStatusError, model.NotificationTypeAll, model.NotificationReasonFetchError)
|
||||
@@ -880,7 +880,7 @@ func (a *App) publishWebsocketEventForPermalinkPost(c request.CTX, post *model.P
|
||||
}
|
||||
|
||||
func (a *App) PatchPost(c request.CTX, postID string, patch *model.PostPatch) (*model.Post, *model.AppError) {
|
||||
post, err := a.GetSinglePost(postID, false)
|
||||
post, err := a.GetSinglePost(c, postID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -971,8 +971,8 @@ func (a *App) GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList
|
||||
return postList, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError) {
|
||||
post, err := a.Srv().Store().Post().GetSingle(postID, includeDeleted)
|
||||
func (a *App) GetSinglePost(rctx request.CTX, postID string, includeDeleted bool) (*model.Post, *model.AppError) {
|
||||
post, err := a.Srv().Store().Post().GetSingle(rctx, postID, includeDeleted)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -1362,7 +1362,7 @@ func (a *App) GetPostsForChannelAroundLastUnread(c request.CTX, channelID, userI
|
||||
}
|
||||
|
||||
func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post, *model.AppError) {
|
||||
post, err := a.Srv().Store().Post().GetSingle(postID, false)
|
||||
post, err := a.Srv().Store().Post().GetSingle(sqlstore.RequestContextWithMaster(c), postID, false)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
@@ -1730,7 +1730,7 @@ func (a *App) SearchPostsForUser(c request.CTX, terms string, userID string, tea
|
||||
func (a *App) GetFileInfosForPostWithMigration(rctx request.CTX, postID string, includeDeleted bool) ([]*model.FileInfo, *model.AppError) {
|
||||
pchan := make(chan store.StoreResult[*model.Post], 1)
|
||||
go func() {
|
||||
post, err := a.Srv().Store().Post().GetSingle(postID, includeDeleted)
|
||||
post, err := a.Srv().Store().Post().GetSingle(rctx, postID, includeDeleted)
|
||||
pchan <- store.StoreResult[*model.Post]{Data: post, NErr: err}
|
||||
close(pchan)
|
||||
}()
|
||||
@@ -2077,7 +2077,7 @@ func (a *App) GetThreadMembershipsForUser(userID, teamID string) ([]*model.Threa
|
||||
}
|
||||
|
||||
func (a *App) GetPostIfAuthorized(c request.CTX, postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError) {
|
||||
post, err := a.GetSinglePost(postID, includeDeleted)
|
||||
post, err := a.GetSinglePost(c, postID, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2269,7 +2269,7 @@ func (a *App) CheckPostReminders(rctx request.CTX) {
|
||||
|
||||
func (a *App) GetPostInfo(c request.CTX, postID string) (*model.PostInfo, *model.AppError) {
|
||||
userID := c.Session().UserId
|
||||
post, appErr := a.GetSinglePost(postID, false)
|
||||
post, appErr := a.GetSinglePost(c, postID, false)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) SaveAcknowledgementForPost(c request.CTX, postID, userID string) (*model.PostAcknowledgement, *model.AppError) {
|
||||
post, err := a.GetSinglePost(postID, false)
|
||||
post, err := a.GetSinglePost(c, postID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (a *App) SaveAcknowledgementForPost(c request.CTX, postID, userID string) (
|
||||
}
|
||||
|
||||
func (a *App) DeleteAcknowledgementForPost(c request.CTX, postID, userID string) *model.AppError {
|
||||
post, err := a.GetSinglePost(postID, false)
|
||||
post, err := a.GetSinglePost(c, postID, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func testSaveAcknowledgementForPost(t *testing.T) {
|
||||
_, err = th.App.SaveAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err = th.App.GetSinglePost(post.Id, false)
|
||||
post, err = th.App.GetSinglePost(th.Context, post.Id, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Greater(t, post.UpdateAt, oldUpdateAt)
|
||||
@@ -91,7 +91,7 @@ func testDeleteAcknowledgementForPost(t *testing.T) {
|
||||
_, err := th.App.SaveAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err = th.App.GetSinglePost(post.Id, false)
|
||||
post, err = th.App.GetSinglePost(th.Context, post.Id, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
oldUpdateAt := post.UpdateAt
|
||||
@@ -99,7 +99,7 @@ func testDeleteAcknowledgementForPost(t *testing.T) {
|
||||
err = th.App.DeleteAcknowledgementForPost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err = th.App.GetSinglePost(post.Id, false)
|
||||
post, err = th.App.GetSinglePost(th.Context, post.Id, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Greater(t, post.UpdateAt, oldUpdateAt)
|
||||
|
||||
@@ -645,7 +645,7 @@ func (a *App) getLinkMetadata(c request.CTX, requestURL string, timestamp int64,
|
||||
if looksLikeAPermalink(requestURL, a.GetSiteURL()) && *a.Config().ServiceSettings.EnablePermalinkPreviews {
|
||||
referencedPostID := requestURL[len(requestURL)-26:]
|
||||
|
||||
referencedPost, appErr := a.GetSinglePost(referencedPostID, false)
|
||||
referencedPost, appErr := a.GetSinglePost(c, referencedPostID, false)
|
||||
// TODO: Look into saving a value in the LinkMetadata.Data field to prevent perpetually re-querying for the deleted post.
|
||||
if appErr != nil {
|
||||
return nil, nil, nil, appErr
|
||||
|
||||
@@ -257,7 +257,7 @@ func TestAttachFilesToPost(t *testing.T) {
|
||||
assert.Len(t, infos, 1)
|
||||
assert.Equal(t, info2.Id, infos[0].Id)
|
||||
|
||||
updated, appErr := th.App.GetSinglePost(post.Id, false)
|
||||
updated, appErr := th.App.GetSinglePost(th.Context, post.Id, false)
|
||||
require.Nil(t, appErr)
|
||||
assert.Len(t, updated.FileIds, 1)
|
||||
assert.Contains(t, updated.FileIds, info2.Id)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) SaveReactionForPost(c request.CTX, reaction *model.Reaction) (*model.Reaction, *model.AppError) {
|
||||
post, err := a.GetSinglePost(reaction.PostId, false)
|
||||
post, err := a.GetSinglePost(c, reaction.PostId, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func populateEmptyReactions(postIDs []string, reactions map[string][]*model.Reac
|
||||
}
|
||||
|
||||
func (a *App) DeleteReactionForPost(c request.CTX, reaction *model.Reaction) *model.AppError {
|
||||
post, err := a.GetSinglePost(reaction.PostId, false)
|
||||
post, err := a.GetSinglePost(c, reaction.PostId, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -969,8 +969,8 @@ func (a *App) GetTeamsForUser(userID string) ([]*model.Team, *model.AppError) {
|
||||
return teams, nil
|
||||
}
|
||||
|
||||
func (a *App) GetTeamMember(c request.CTX, teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
teamMember, err := a.Srv().Store().Team().GetMember(sqlstore.RequestContextWithMaster(c), teamID, userID)
|
||||
func (a *App) GetTeamMember(rctx request.CTX, teamID, userID string) (*model.TeamMember, *model.AppError) {
|
||||
teamMember, err := a.Srv().Store().Team().GetMember(sqlstore.RequestContextWithMaster(rctx), teamID, userID)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
|
||||
@@ -2723,7 +2723,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea
|
||||
return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
post, appErr := a.GetSinglePost(threadID, false)
|
||||
post, appErr := a.GetSinglePost(c, threadID, false)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
@@ -2772,7 +2772,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea
|
||||
}
|
||||
|
||||
func (a *App) UpdateThreadReadForUserByPost(c request.CTX, currentSessionId, userID, teamID, threadID, postID string) (*model.ThreadResponse, *model.AppError) {
|
||||
post, err := a.GetSinglePost(postID, false)
|
||||
post, err := a.GetSinglePost(c, postID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -2805,7 +2805,7 @@ func (a *App) UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, t
|
||||
return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
post, err := a.GetSinglePost(threadID, false)
|
||||
post, err := a.GetSinglePost(c, threadID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user