diff --git a/app/app_iface.go b/app/app_iface.go index a39162fc3e..f59d0c3183 100644 --- a/app/app_iface.go +++ b/app/app_iface.go @@ -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) diff --git a/app/opentracing/opentracing_layer.go b/app/opentracing/opentracing_layer.go index 3947de1ec7..7238a27592 100644 --- a/app/opentracing/opentracing_layer.go +++ b/app/opentracing/opentracing_layer.go @@ -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") diff --git a/app/post.go b/app/post.go index 0f07b7e57b..005fcfaa83 100644 --- a/app/post.go +++ b/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)) } } diff --git a/app/post_metadata_test.go b/app/post_metadata_test.go index 4204008937..83a1fc0069 100644 --- a/app/post_metadata_test.go +++ b/app/post_metadata_test.go @@ -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()