| 410 | } |
| 411 | |
| 412 | func DeleteOldLog(ctx context.Context, targetTimestamp int64, limit int) (int64, error) { |
| 413 | var total int64 = 0 |
| 414 | |
| 415 | for { |
| 416 | if nil != ctx.Err() { |
| 417 | return total, ctx.Err() |
| 418 | } |
| 419 | |
| 420 | result := LOG_DB.Where("created_at < ?", targetTimestamp).Limit(limit).Delete(&Log{}) |
| 421 | if nil != result.Error { |
| 422 | return total, result.Error |
| 423 | } |
| 424 | |
| 425 | total += result.RowsAffected |
| 426 | |
| 427 | if result.RowsAffected < int64(limit) { |
| 428 | break |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | return total, nil |
| 433 | } |
| 434 | |
| 435 | // DeleteLogsByTimeRange 根据时间范围删除日志 |
| 436 | func DeleteLogsByTimeRange(ctx context.Context, startTimestamp int64, endTimestamp int64, limit int) (int64, error) { |