MM-19877: Remove references to PermanentDeleteBatch from audit store (#13393)
* MM-19877: Remove references to PermanentDeleteBatch from audit store
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
68e0b1fdc2
Коммит
e48d093d01
@@ -71,23 +71,3 @@ func (s SqlAuditStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlAuditStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
var query string
|
||||
if s.DriverName() == "postgres" {
|
||||
query = "DELETE from Audits WHERE Id = any (array (SELECT Id FROM Audits WHERE CreateAt < :EndTime LIMIT :Limit))"
|
||||
} else {
|
||||
query = "DELETE from Audits WHERE CreateAt < :EndTime LIMIT :Limit"
|
||||
}
|
||||
|
||||
sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"EndTime": endTime, "Limit": limit})
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlAuditStore.PermanentDeleteBatch", "store.sql_audit.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
rowsAffected, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlAuditStore.PermanentDeleteBatch", "store.sql_audit.permanent_delete_batch.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
@@ -328,7 +328,6 @@ type AuditStore interface {
|
||||
Save(audit *model.Audit) *model.AppError
|
||||
Get(user_id string, offset int, limit int) (model.Audits, *model.AppError)
|
||||
PermanentDeleteByUser(userId string) *model.AppError
|
||||
PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError)
|
||||
}
|
||||
|
||||
type ClusterDiscoveryStore interface {
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
|
||||
func TestAuditStore(t *testing.T, ss store.Store) {
|
||||
t.Run("", func(t *testing.T) { testAuditStore(t, ss) })
|
||||
t.Run("PermanentDeleteBatch", func(t *testing.T) { testAuditStorePermanentDeleteBatch(t, ss) })
|
||||
}
|
||||
|
||||
func testAuditStore(t *testing.T, ss store.Store) {
|
||||
@@ -49,29 +48,3 @@ func testAuditStore(t *testing.T, ss store.Store) {
|
||||
|
||||
require.Nil(t, ss.Audit().PermanentDeleteByUser(audit.UserId))
|
||||
}
|
||||
|
||||
func testAuditStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
a1 := &model.Audit{UserId: model.NewId(), IpAddress: "ipaddress", Action: "Action"}
|
||||
require.Nil(t, ss.Audit().Save(a1))
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
a2 := &model.Audit{UserId: a1.UserId, IpAddress: "ipaddress", Action: "Action"}
|
||||
require.Nil(t, ss.Audit().Save(a2))
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
cutoff := model.GetMillis()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
a3 := &model.Audit{UserId: a1.UserId, IpAddress: "ipaddress", Action: "Action"}
|
||||
require.Nil(t, ss.Audit().Save(a3))
|
||||
|
||||
audits, err := ss.Audit().Get(a1.UserId, 0, 100)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, audits, 3)
|
||||
|
||||
_, err = ss.Audit().PermanentDeleteBatch(cutoff, 1000000)
|
||||
require.Nil(t, err)
|
||||
|
||||
audits, err = ss.Audit().Get(a1.UserId, 0, 100)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, audits, 1)
|
||||
|
||||
require.Nil(t, ss.Audit().PermanentDeleteByUser(a1.UserId))
|
||||
}
|
||||
|
||||
@@ -39,29 +39,6 @@ func (_m *AuditStore) Get(user_id string, offset int, limit int) (model.Audits,
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteBatch provides a mock function with given fields: endTime, limit
|
||||
func (_m *AuditStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
ret := _m.Called(endTime, limit)
|
||||
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(int64, int64) int64); ok {
|
||||
r0 = rf(endTime, limit)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int64, int64) *model.AppError); ok {
|
||||
r1 = rf(endTime, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteByUser provides a mock function with given fields: userId
|
||||
func (_m *AuditStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
@@ -344,22 +344,6 @@ func (s *TimerLayerAuditStore) Get(user_id string, offset int, limit int) (model
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerAuditStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.AuditStore.PermanentDeleteBatch(endTime, limit)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if resultVar1 == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("AuditStore.PermanentDeleteBatch", success, elapsed)
|
||||
}
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerAuditStore) PermanentDeleteByUser(userId string) *model.AppError {
|
||||
start := timemodule.Now()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user