mirror of
https://github.com/DullJZ/s3-balance.git
synced 2026-07-03 09:01:22 +08:00
Fix: Add boundary checks for negative increment values
This commit is contained in:
@@ -680,6 +680,14 @@ func (s *Service) ArchiveMonthlyStats(year, month int) error {
|
||||
// 如果是首次运行(没有历史数据),incrementA/B 可能等于累计值
|
||||
// 这是预期行为:首月记录的就是从0到当前的增量
|
||||
|
||||
// 边界情况:如果计算出负值,说明数据不一致,设置为0
|
||||
if incrementA < 0 {
|
||||
incrementA = 0
|
||||
}
|
||||
if incrementB < 0 {
|
||||
incrementB = 0
|
||||
}
|
||||
|
||||
monthlyStats := BucketMonthlyStats{
|
||||
BucketName: stat.BucketName,
|
||||
Year: year,
|
||||
@@ -762,6 +770,14 @@ func (s *Service) GetCurrentMonthStats() ([]BucketMonthlyStats, error) {
|
||||
incrementA := current.OperationCountA - lastMonthCumulativeA[current.BucketName]
|
||||
incrementB := current.OperationCountB - lastMonthCumulativeB[current.BucketName]
|
||||
|
||||
// 边界情况:如果计算出负值,说明数据不一致,设置为0
|
||||
if incrementA < 0 {
|
||||
incrementA = 0
|
||||
}
|
||||
if incrementB < 0 {
|
||||
incrementB = 0
|
||||
}
|
||||
|
||||
result = append(result, BucketMonthlyStats{
|
||||
BucketName: current.BucketName,
|
||||
Year: year,
|
||||
|
||||
Reference in New Issue
Block a user