mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-06 21:25:04 +03:00
dbb6212988
Restore usable clients when renewed, avoid duplicate reset updates, and prioritize operator writes in the serialized traffic writer. Preserve manual disables and keep every inbound consistent after traffic resets.
34 lines
1007 B
Go
34 lines
1007 B
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/xray"
|
|
)
|
|
|
|
// AddTuicTrafficBatch commits a journal batch and its receipt atomically. A
|
|
// retained journal can therefore be replayed after an ambiguous commit result.
|
|
func (s *InboundService) AddTuicTrafficBatch(id string, traffic []*xray.ClientTraffic) error {
|
|
if id == "" {
|
|
return errors.New("TUIC traffic batch has no ID")
|
|
}
|
|
// The receipt journal is periodic accounting, not an operator action.
|
|
return submitTrafficWriteBackground(func() error {
|
|
return database.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
result := tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&model.TuicTrafficReceipt{ID: id})
|
|
if result.Error != nil {
|
|
return result.Error
|
|
}
|
|
if result.RowsAffected == 0 {
|
|
return nil
|
|
}
|
|
return s.addClientTraffic(tx, traffic)
|
|
})
|
|
})
|
|
}
|