fix: use GORM v2 row locking for subscription resets (#6057)

* fix: use GORM v2 row locking for subscription resets

* docs: codify GORM row locking rules
This commit is contained in:
Seefs
2026-07-10 10:21:00 +08:00
committed by GitHub
parent 246d62aa5e
commit 4e570389dd
2 changed files with 3 additions and 2 deletions
+2 -2
View File
@@ -1027,7 +1027,7 @@ func adminResetUserSubscriptionsByPlanTx(tx *gorm.DB, userId int, plan *Subscrip
return nil, errors.New("invalid reset args")
}
var subs []UserSubscription
if err := tx.Set("gorm:query_option", "FOR UPDATE").
if err := lockForUpdate(tx).
Where("user_id = ? AND plan_id = ? AND status = ? AND end_time > ?", userId, plan.Id, "active", now).
Order("end_time asc, id asc").
Find(&subs).Error; err != nil {
@@ -1049,7 +1049,7 @@ func adminResetPlanSubscriptionsTx(tx *gorm.DB, plan *SubscriptionPlan, now int6
return nil, errors.New("invalid reset args")
}
var subs []UserSubscription
if err := tx.Set("gorm:query_option", "FOR UPDATE").
if err := lockForUpdate(tx).
Where("plan_id = ? AND status = ? AND end_time > ?", plan.Id, "active", now).
Order("user_id asc, end_time asc, id asc").
Find(&subs).Error; err != nil {