Skip to content

Commit

Permalink
[MM-53291] Data retention improvements cherry pick 7.8 (#24492)
Browse files Browse the repository at this point in the history
* cherry picking data retention fix and fixing conflicts
---------
Co-authored-by: Mattermost Build <build@mattermost.com>
  • Loading branch information
BenCookie95 committed Sep 7, 2023
1 parent 2932875 commit 58a74d7
Show file tree
Hide file tree
Showing 27 changed files with 817 additions and 269 deletions.
4 changes: 4 additions & 0 deletions app/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,10 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A
return model.NewAppError("PermanentDeleteUser", "app.post.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}

if err := a.Srv().Store().Reaction().PermanentDeleteByUser(user.Id); err != nil {
return model.NewAppError("PermanentDeleteUser", "app.reaction.permanent_delete_by_user.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
}

if err := a.Srv().Store().Bot().PermanentDelete(user.Id); err != nil {
var invErr *store.ErrInvalidInput
switch {
Expand Down
4 changes: 4 additions & 0 deletions db/migrations/migrations.list
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ db/migrations/mysql/000105_remove_tokens.down.sql
db/migrations/mysql/000105_remove_tokens.up.sql
db/migrations/mysql/000107_threadmemberships_cleanup.down.sql
db/migrations/mysql/000107_threadmemberships_cleanup.up.sql
db/migrations/mysql/000113_create_retentionidsfordeletion_table.down.sql
db/migrations/mysql/000113_create_retentionidsfordeletion_table.up.sql
db/migrations/postgres/000001_create_teams.down.sql
db/migrations/postgres/000001_create_teams.up.sql
db/migrations/postgres/000002_create_team_members.down.sql
Expand Down Expand Up @@ -412,3 +414,5 @@ db/migrations/postgres/000105_remove_tokens.down.sql
db/migrations/postgres/000105_remove_tokens.up.sql
db/migrations/postgres/000107_threadmemberships_cleanup.down.sql
db/migrations/postgres/000107_threadmemberships_cleanup.up.sql
db/migrations/postgres/000113_create_retentionidsfordeletion_table.down.sql
db/migrations/postgres/000113_create_retentionidsfordeletion_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS RetentionIdsForDeletion;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS RetentionIdsForDeletion (
Id varchar(26) NOT NULL,
TableName varchar(64),
Ids json,
PRIMARY KEY (Id),
KEY idx_retentionidsfordeletion_tablename (TableName)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP INDEX IF EXISTS idx_retentionidsfordeletion_tablename;

DROP TABLE IF EXISTS retentionidsfordeletion;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS retentionidsfordeletion (
id varchar(26) PRIMARY KEY,
tablename varchar(64),
ids varchar(26)[]
);

CREATE INDEX IF NOT EXISTS idx_retentionidsfordeletion_tablename ON retentionidsfordeletion (tablename);
4 changes: 4 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6299,6 +6299,10 @@
"id": "app.reaction.get_for_post.app_error",
"translation": "Unable to get reactions for post."
},
{
"id": "app.reaction.permanent_delete_by_user.app_error",
"translation": "Unable to delete reactions for user."
},
{
"id": "app.reaction.save.save.app_error",
"translation": "Unable to save reaction."
Expand Down
5 changes: 5 additions & 0 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const (
DataRetentionSettingsDefaultDeletionJobStartTime = "02:00"
DataRetentionSettingsDefaultBatchSize = 3000
DataRetentionSettingsDefaultTimeBetweenBatchesMilliseconds = 100
DataRetentionSettingsDefaultRetentionIdsBatchSize = 100

PluginSettingsDefaultDirectory = "./plugins"
PluginSettingsDefaultClientDirectory = "./client/plugins"
Expand Down Expand Up @@ -2716,6 +2717,7 @@ type DataRetentionSettings struct {
DeletionJobStartTime *string `access:"compliance_data_retention_policy"`
BatchSize *int `access:"compliance_data_retention_policy"`
TimeBetweenBatchesMilliseconds *int `access:"compliance_data_retention_policy"`
RetentionIdsBatchSize *int `access:"compliance_data_retention_policy"`
}

func (s *DataRetentionSettings) SetDefaults() {
Expand Down Expand Up @@ -2754,6 +2756,9 @@ func (s *DataRetentionSettings) SetDefaults() {
if s.TimeBetweenBatchesMilliseconds == nil {
s.TimeBetweenBatchesMilliseconds = NewInt(DataRetentionSettingsDefaultTimeBetweenBatchesMilliseconds)
}
if s.RetentionIdsBatchSize == nil {
s.RetentionIdsBatchSize = NewInt(DataRetentionSettingsDefaultRetentionIdsBatchSize)
}
}

type JobSettings struct {
Expand Down
12 changes: 12 additions & 0 deletions model/data_retention_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,15 @@ type RetentionPolicyCursor struct {
TeamPoliciesDone bool
GlobalPoliciesDone bool
}

type RetentionIdsForDeletion struct {
Id string
TableName string
Ids []string
}

func (r *RetentionIdsForDeletion) PreSave() {
if r.Id == "" {
r.Id = NewId()
}
}
3 changes: 0 additions & 3 deletions model/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ type FeatureFlags struct {
GlobalDrafts bool

OnboardingTourTips bool

DataRetentionConcurrencyEnabled bool
}

func (f *FeatureFlags) SetDefaults() {
Expand Down Expand Up @@ -110,7 +108,6 @@ func (f *FeatureFlags) SetDefaults() {
f.GlobalDrafts = true
f.WysiwygEditor = false
f.OnboardingTourTips = true
f.DataRetentionConcurrencyEnabled = true
}

func (f *FeatureFlags) Plugins() map[string]string {
Expand Down
1 change: 1 addition & 0 deletions services/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ func (ts *TelemetryService) trackConfig() {
"deletion_job_start_time": *cfg.DataRetentionSettings.DeletionJobStartTime,
"batch_size": *cfg.DataRetentionSettings.BatchSize,
"time_between_batches": *cfg.DataRetentionSettings.TimeBetweenBatchesMilliseconds,
"retention_ids_batch_size": *cfg.DataRetentionSettings.RetentionIdsBatchSize,
"cleanup_jobs_threshold_days": *cfg.JobSettings.CleanupJobsThresholdDays,
"cleanup_config_threshold_days": *cfg.JobSettings.CleanupConfigThresholdDays,
})
Expand Down
62 changes: 40 additions & 22 deletions store/opentracinglayer/opentracinglayer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 47 additions & 26 deletions store/retrylayer/retrylayer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions store/sqlstore/channel_member_history_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (s SqlChannelMemberHistoryStore) PermanentDeleteBatchForRetentionPolicies(n
NowMillis: now,
GlobalPolicyEndTime: globalPolicyEndTime,
Limit: limit,
StoreDeletedIds: false,
}, s.SqlStore, cursor)
}

Expand Down

0 comments on commit 58a74d7

Please sign in to comment.