[GH-25484] Fix draft removal on post deletion (#25715)
* [GH-25484] Fix draft removal on post deletion * [GH-25484] Add batch migration to remove orphan drafts * [GH-25484] Fix tests of migration and draft store * [GH-25484] Remove translation file changes. * [GH-25484] Remove translation file changes. --------- Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com> Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
435da9bea7
Коммит
3ac6edb406
@@ -628,6 +628,27 @@ func (s *Server) doDeleteEmptyDraftsMigration(c request.CTX) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) doDeleteOrphanDraftsMigration(c request.CTX) {
|
||||
// If the migration is already marked as completed, don't do it again.
|
||||
if _, err := s.Store().System().GetByName(model.MigrationKeyDeleteOrphanDrafts); err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
jobs, err := s.Store().Job().GetAllByTypeAndStatus(c, model.JobTypeDeleteOrphanDraftsMigration, model.JobStatusPending)
|
||||
if err != nil {
|
||||
mlog.Fatal("failed to get jobs by type and status", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
if len(jobs) > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if _, appErr := s.Jobs.CreateJobOnce(c, model.JobTypeDeleteOrphanDraftsMigration, nil); appErr != nil {
|
||||
mlog.Fatal("failed to start job for deleting orphan drafts", mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) DoAppMigrations() {
|
||||
a.Srv().doAppMigrations()
|
||||
}
|
||||
@@ -654,4 +675,5 @@ func (s *Server) doAppMigrations() {
|
||||
s.doElasticsearchFixChannelIndex(c)
|
||||
s.doCloudS3PathMigrations(c)
|
||||
s.doDeleteEmptyDraftsMigration(c)
|
||||
s.doDeleteOrphanDraftsMigration(c)
|
||||
}
|
||||
|
||||
@@ -1417,11 +1417,23 @@ func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post,
|
||||
}
|
||||
})
|
||||
|
||||
// delete drafts associated with the post when deleting the post
|
||||
a.Srv().Go(func() {
|
||||
a.deleteDraftsAssociatedWithPost(c, channel, post)
|
||||
})
|
||||
|
||||
a.invalidateCacheForChannelPosts(post.ChannelId)
|
||||
|
||||
return post, nil
|
||||
}
|
||||
|
||||
func (a *App) deleteDraftsAssociatedWithPost(c request.CTX, channel *model.Channel, post *model.Post) {
|
||||
if err := a.Srv().Store().Draft().DeleteDraftsAssociatedWithPost(channel.Id, post.Id); err != nil {
|
||||
c.Logger().Error("Failed to delete drafts associated with post when deleting post", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) deleteFlaggedPosts(c request.CTX, postID string) {
|
||||
if err := a.Srv().Store().Preference().DeleteCategoryAndName(model.PreferenceCategoryFlaggedPost, postID); err != nil {
|
||||
c.Logger().Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
|
||||
|
||||
@@ -41,6 +41,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs/active_users"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs/cleanup_desktop_tokens"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs/delete_empty_drafts_migration"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs/delete_orphan_drafts_migration"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs/expirynotify"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs/export_delete"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/jobs/export_process"
|
||||
@@ -1589,6 +1590,11 @@ func (s *Server) initJobs() {
|
||||
delete_empty_drafts_migration.MakeWorker(s.Jobs, s.Store(), New(ServerConnector(s.Channels()))),
|
||||
nil)
|
||||
|
||||
s.Jobs.RegisterJobType(
|
||||
model.JobTypeDeleteOrphanDraftsMigration,
|
||||
delete_orphan_drafts_migration.MakeWorker(s.Jobs, s.Store(), New(ServerConnector(s.Channels()))),
|
||||
nil)
|
||||
|
||||
s.Jobs.RegisterJobType(
|
||||
model.JobTypeExportDelete,
|
||||
export_delete.MakeWorker(s.Jobs, New(ServerConnector(s.Channels()))),
|
||||
|
||||
Ссылка в новой задаче
Block a user