summaryrefslogtreecommitdiffstats
path: root/store/sql_file_info_store.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-09-15 17:35:55 +0100
committerChristopher Speller <crspeller@gmail.com>2017-09-15 09:35:55 -0700
commit8195c80aa12136838ff4491fac989e0b946382b1 (patch)
treeda24729af5acbd3349c75923d346cfa7aa9ad95c /store/sql_file_info_store.go
parent2628022275ef64fde95545abe4634b4bd7177844 (diff)
downloadchat-8195c80aa12136838ff4491fac989e0b946382b1.tar.gz
chat-8195c80aa12136838ff4491fac989e0b946382b1.tar.bz2
chat-8195c80aa12136838ff4491fac989e0b946382b1.zip
PLT-7639: Batch delete methods for data retention. (#7444)
Diffstat (limited to 'store/sql_file_info_store.go')
-rw-r--r--store/sql_file_info_store.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/store/sql_file_info_store.go b/store/sql_file_info_store.go
index eab83992f..4cd574b13 100644
--- a/store/sql_file_info_store.go
+++ b/store/sql_file_info_store.go
@@ -281,3 +281,36 @@ func (fs SqlFileInfoStore) PermanentDelete(fileId string) StoreChannel {
return storeChannel
}
+
+func (s SqlFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ var query string
+ if *utils.Cfg.SqlSettings.DriverName == "postgres" {
+ query = "DELETE from FileInfo WHERE Id = any (array (SELECT Id FROM FileInfo WHERE CreateAt < :EndTime LIMIT :Limit))"
+ } else {
+ query = "DELETE from FileInfo 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("SqlFileInfoStore.PermanentDeleteBatch", "store.sql_file_info.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
+ } else {
+ rowsAffected, err1 := sqlResult.RowsAffected()
+ if err1 != nil {
+ result.Err = model.NewAppError("SqlFileInfoStore.PermanentDeleteBatch", "store.sql_file_info.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
+ result.Data = int64(0)
+ } else {
+ result.Data = rowsAffected
+ }
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}