diff options
author | George Goldberg <george@gberg.me> | 2017-09-15 17:35:55 +0100 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-09-15 09:35:55 -0700 |
commit | 8195c80aa12136838ff4491fac989e0b946382b1 (patch) | |
tree | da24729af5acbd3349c75923d346cfa7aa9ad95c /store/sql_supplier_reactions.go | |
parent | 2628022275ef64fde95545abe4634b4bd7177844 (diff) | |
download | chat-8195c80aa12136838ff4491fac989e0b946382b1.tar.gz chat-8195c80aa12136838ff4491fac989e0b946382b1.tar.bz2 chat-8195c80aa12136838ff4491fac989e0b946382b1.zip |
PLT-7639: Batch delete methods for data retention. (#7444)
Diffstat (limited to 'store/sql_supplier_reactions.go')
-rw-r--r-- | store/sql_supplier_reactions.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/store/sql_supplier_reactions.go b/store/sql_supplier_reactions.go index 2293a2f88..94a980455 100644 --- a/store/sql_supplier_reactions.go +++ b/store/sql_supplier_reactions.go @@ -5,8 +5,10 @@ package store import ( "context" + "net/http" l4g "github.com/alecthomas/log4go" + "github.com/mattermost/gorp" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" @@ -140,6 +142,32 @@ func (s *SqlSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiN return result } +func (s *SqlSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { + result := NewSupplierResult() + + var query string + if *utils.Cfg.SqlSettings.DriverName == "postgres" { + query = "DELETE from Reactions WHERE Id = any (array (SELECT Id FROM Reactions WHERE CreateAt < :EndTime LIMIT :Limit))" + } else { + query = "DELETE from Reactions WHERE CreateAt < :EndTime LIMIT :Limit" + } + + sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"EndTime": endTime, "Limit": limit}) + if err != nil { + result.Err = model.NewAppError("SqlReactionStore.PermanentDeleteBatch", "store.sql_reaction.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError) + } else { + rowsAffected, err1 := sqlResult.RowsAffected() + if err1 != nil { + result.Err = model.NewAppError("SqlReactionStore.PermanentDeleteBatch", "store.sql_reaction.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError) + result.Data = int64(0) + } else { + result.Data = rowsAffected + } + } + + return result +} + func saveReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.Reaction) error { if err := transaction.Insert(reaction); err != nil { return err |