mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-18 05:47:28 +00:00
🐛 fix(subscription): avoid pre-consume lookup noise
Use a RowsAffected check for the idempotency lookup so missing records no longer surface as "record not found" errors while preserving behavior.
This commit is contained in:
@@ -838,7 +838,11 @@ func PreConsumeUserSubscription(requestId string, userId int, modelName string,
|
||||
|
||||
err := DB.Transaction(func(tx *gorm.DB) error {
|
||||
var existing SubscriptionPreConsumeRecord
|
||||
if err := tx.Where("request_id = ?", requestId).First(&existing).Error; err == nil {
|
||||
query := tx.Where("request_id = ?", requestId).Limit(1).Find(&existing)
|
||||
if query.Error != nil {
|
||||
return query.Error
|
||||
}
|
||||
if query.RowsAffected > 0 {
|
||||
if existing.Status == "refunded" {
|
||||
return errors.New("subscription pre-consume already refunded")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user