mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Fix possible race (#18328)
This commit is contained in:
@@ -500,7 +500,6 @@ type AppIface interface {
|
||||
DeleteEmoji(emoji *model.Emoji) *model.AppError
|
||||
DeleteEphemeralPost(userID, postID string)
|
||||
DeleteExport(name string) *model.AppError
|
||||
DeleteFlaggedPosts(postID string)
|
||||
DeleteGroup(groupID string) (*model.Group, *model.AppError)
|
||||
DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
||||
DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError)
|
||||
@@ -509,7 +508,6 @@ type AppIface interface {
|
||||
DeleteOutgoingWebhook(hookID string) *model.AppError
|
||||
DeletePluginKey(pluginID string, key string) *model.AppError
|
||||
DeletePost(postID, deleteByID string) (*model.Post, *model.AppError)
|
||||
DeletePostFiles(post *model.Post)
|
||||
DeletePreferences(userID string, preferences model.Preferences) *model.AppError
|
||||
DeleteReactionForPost(c *request.Context, reaction *model.Reaction) *model.AppError
|
||||
DeleteRemoteCluster(remoteClusterId string) (bool, *model.AppError)
|
||||
|
||||
@@ -2932,21 +2932,6 @@ func (a *OpenTracingAppLayer) DeleteExport(name string) *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DeleteFlaggedPosts(postID string) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DeleteFlaggedPosts")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
a.app.DeleteFlaggedPosts(postID)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DeleteGroup")
|
||||
@@ -3145,21 +3130,6 @@ func (a *OpenTracingAppLayer) DeletePost(postID string, deleteByID string) (*mod
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DeletePostFiles(post *model.Post) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DeletePostFiles")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
a.app.DeletePostFiles(post)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) DeletePreferences(userID string, preferences model.Preferences) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DeletePreferences")
|
||||
|
||||
22
app/post.go
22
app/post.go
@@ -1172,11 +1172,13 @@ func (a *App) DeletePost(postID, deleteByID string) (*model.Post, *model.AppErro
|
||||
adminMessage.GetBroadcast().ContainsSensitiveData = true
|
||||
a.Publish(adminMessage)
|
||||
|
||||
if len(post.FileIds) > 0 {
|
||||
a.Srv().Go(func() {
|
||||
a.deletePostFiles(post.Id)
|
||||
})
|
||||
}
|
||||
a.Srv().Go(func() {
|
||||
a.DeletePostFiles(post)
|
||||
})
|
||||
a.Srv().Go(func() {
|
||||
a.DeleteFlaggedPosts(post.Id)
|
||||
a.deleteFlaggedPosts(post.Id)
|
||||
})
|
||||
|
||||
a.invalidateCacheForChannelPosts(post.ChannelId)
|
||||
@@ -1184,20 +1186,16 @@ func (a *App) DeletePost(postID, deleteByID string) (*model.Post, *model.AppErro
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (a *App) DeleteFlaggedPosts(postID string) {
|
||||
func (a *App) deleteFlaggedPosts(postID string) {
|
||||
if err := a.Srv().Store.Preference().DeleteCategoryAndName(model.PreferenceCategoryFlaggedPost, postID); err != nil {
|
||||
mlog.Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) DeletePostFiles(post *model.Post) {
|
||||
if len(post.FileIds) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := a.Srv().Store.FileInfo().DeleteForPost(post.Id); err != nil {
|
||||
mlog.Warn("Encountered error when deleting files for post", mlog.String("post_id", post.Id), mlog.Err(err))
|
||||
func (a *App) deletePostFiles(postID string) {
|
||||
if _, err := a.Srv().Store.FileInfo().DeleteForPost(postID); err != nil {
|
||||
mlog.Warn("Encountered error when deleting files for post", mlog.String("post_id", postID), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -521,7 +521,6 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("no metadata for deleted posts", func(t *testing.T) {
|
||||
t.Skip("MM-37757")
|
||||
th := setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user