MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / batchUpdate

Function batchUpdate

model/utils.go:51–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49}
50
51func batchUpdate() {
52 // check if there's any data to update
53 hasData := false
54 for i := 0; i < BatchUpdateTypeCount; i++ {
55 batchUpdateLocks[i].Lock()
56 if len(batchUpdateStores[i]) > 0 {
57 hasData = true
58 batchUpdateLocks[i].Unlock()
59 break
60 }
61 batchUpdateLocks[i].Unlock()
62 }
63
64 if !hasData {
65 return
66 }
67
68 common.SysLog("batch update started")
69 for i := 0; i < BatchUpdateTypeCount; i++ {
70 batchUpdateLocks[i].Lock()
71 store := batchUpdateStores[i]
72 batchUpdateStores[i] = make(map[int]int)
73 batchUpdateLocks[i].Unlock()
74 // TODO: maybe we can combine updates with same key?
75 for key, value := range store {
76 switch i {
77 case BatchUpdateTypeUserQuota:
78 err := increaseUserQuota(key, value)
79 if err != nil {
80 common.SysError("failed to batch update user quota: " + err.Error())
81 }
82 case BatchUpdateTypeTokenQuota:
83 err := increaseTokenQuota(key, value)
84 if err != nil {
85 common.SysError("failed to batch update token quota: " + err.Error())
86 }
87 case BatchUpdateTypeUsedQuota:
88 updateUserUsedQuota(key, value)
89 case BatchUpdateTypeRequestCount:
90 updateUserRequestCount(key, value)
91 case BatchUpdateTypeChannelUsedQuota:
92 updateChannelUsedQuota(key, value)
93 }
94 }
95 }
96 common.SysLog("batch update finished")
97}
98
99func RecordExist(err error) (bool, error) {
100 if err == nil {

Callers 1

InitBatchUpdaterFunction · 0.85

Calls 8

SysLogFunction · 0.92
SysErrorFunction · 0.92
increaseUserQuotaFunction · 0.85
increaseTokenQuotaFunction · 0.85
updateUserUsedQuotaFunction · 0.85
updateUserRequestCountFunction · 0.85
updateChannelUsedQuotaFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected