(id int, quota int, db bool)
| 1076 | } |
| 1077 | |
| 1078 | func DecreaseUserQuota(id int, quota int, db bool) (err error) { |
| 1079 | if quota < 0 { |
| 1080 | return errors.New("quota 不能为负数!") |
| 1081 | } |
| 1082 | gopool.Go(func() { |
| 1083 | err := cacheDecrUserQuota(id, int64(quota)) |
| 1084 | if err != nil { |
| 1085 | common.SysLog("failed to decrease user quota: " + err.Error()) |
| 1086 | } |
| 1087 | }) |
| 1088 | if !db && common.BatchUpdateEnabled { |
| 1089 | addNewRecord(BatchUpdateTypeUserQuota, id, -quota) |
| 1090 | return nil |
| 1091 | } |
| 1092 | return decreaseUserQuota(id, quota) |
| 1093 | } |
| 1094 | |
| 1095 | func decreaseUserQuota(id int, quota int) (err error) { |
| 1096 | err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error |
no test coverage detected