()
| 46 | } |
| 47 | |
| 48 | func batchUpdate() { |
| 49 | logger.SysLog("batch update started") |
| 50 | for i := 0; i < BatchUpdateTypeCount; i++ { |
| 51 | batchUpdateLocks[i].Lock() |
| 52 | store := batchUpdateStores[i] |
| 53 | batchUpdateStores[i] = make(map[int]int64) |
| 54 | batchUpdateLocks[i].Unlock() |
| 55 | // TODO: maybe we can combine updates with same key? |
| 56 | for key, value := range store { |
| 57 | switch i { |
| 58 | case BatchUpdateTypeUserQuota: |
| 59 | err := increaseUserQuota(key, value) |
| 60 | if err != nil { |
| 61 | logger.SysError("failed to batch update user quota: " + err.Error()) |
| 62 | } |
| 63 | case BatchUpdateTypeTokenQuota: |
| 64 | err := increaseTokenQuota(key, value) |
| 65 | if err != nil { |
| 66 | logger.SysError("failed to batch update token quota: " + err.Error()) |
| 67 | } |
| 68 | case BatchUpdateTypeUsedQuota: |
| 69 | updateUserUsedQuota(key, value) |
| 70 | case BatchUpdateTypeRequestCount: |
| 71 | updateUserRequestCount(key, int(value)) |
| 72 | case BatchUpdateTypeChannelUsedQuota: |
| 73 | updateChannelUsedQuota(key, value) |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | logger.SysLog("batch update finished") |
| 78 | } |
no test coverage detected