mirror of
https://github.com/DullJZ/s3-balance.git
synced 2026-09-06 16:27:38 +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 可能等于累计值
|
// 如果是首次运行(没有历史数据),incrementA/B 可能等于累计值
|
||||||
// 这是预期行为:首月记录的就是从0到当前的增量
|
// 这是预期行为:首月记录的就是从0到当前的增量
|
||||||
|
|
||||||
|
// 边界情况:如果计算出负值,说明数据不一致,设置为0
|
||||||
|
if incrementA < 0 {
|
||||||
|
incrementA = 0
|
||||||
|
}
|
||||||
|
if incrementB < 0 {
|
||||||
|
incrementB = 0
|
||||||
|
}
|
||||||
|
|
||||||
monthlyStats := BucketMonthlyStats{
|
monthlyStats := BucketMonthlyStats{
|
||||||
BucketName: stat.BucketName,
|
BucketName: stat.BucketName,
|
||||||
Year: year,
|
Year: year,
|
||||||
@@ -762,6 +770,14 @@ func (s *Service) GetCurrentMonthStats() ([]BucketMonthlyStats, error) {
|
|||||||
incrementA := current.OperationCountA - lastMonthCumulativeA[current.BucketName]
|
incrementA := current.OperationCountA - lastMonthCumulativeA[current.BucketName]
|
||||||
incrementB := current.OperationCountB - lastMonthCumulativeB[current.BucketName]
|
incrementB := current.OperationCountB - lastMonthCumulativeB[current.BucketName]
|
||||||
|
|
||||||
|
// 边界情况:如果计算出负值,说明数据不一致,设置为0
|
||||||
|
if incrementA < 0 {
|
||||||
|
incrementA = 0
|
||||||
|
}
|
||||||
|
if incrementB < 0 {
|
||||||
|
incrementB = 0
|
||||||
|
}
|
||||||
|
|
||||||
result = append(result, BucketMonthlyStats{
|
result = append(result, BucketMonthlyStats{
|
||||||
BucketName: current.BucketName,
|
BucketName: current.BucketName,
|
||||||
Year: year,
|
Year: year,
|
||||||
|
|||||||
Reference in New Issue
Block a user