| 1385 | } |
| 1386 | |
| 1387 | func DecreaseUserQuota(id int, quota int, db bool) (err error) { |
| 1388 | if quota < 0 { |
| 1389 | return errors.New("quota cannot be negative") |
| 1390 | } |
| 1391 | gopool.Go(func() { |
| 1392 | err := cacheDecrUserQuota(id, int64(quota)) |
| 1393 | if err != nil { |
| 1394 | common.SysLog(common.LogText("failed to decrease user quota: %s", err.Error())) |
| 1395 | } |
| 1396 | }) |
| 1397 | if !db && common.BatchUpdateEnabled { |
| 1398 | addNewRecord(BatchUpdateTypeUserQuota, id, -quota) |
| 1399 | return nil |
| 1400 | } |
| 1401 | return decreaseUserQuota(id, quota) |
| 1402 | } |
| 1403 | |
| 1404 | func decreaseUserQuota(id int, quota int) (err error) { |
| 1405 | err = DB.Model(&User{}).Where("id = ?", id).Update("quota", gorm.Expr("quota - ?", quota)).Error |