mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-19 00:46:37 +08:00
perf: 优化数据看板性能
This commit is contained in:
parent
75b6327f4f
commit
1618a8c9fc
@ -79,7 +79,7 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke
|
||||
common.LogError(ctx, "failed to record log: "+err.Error())
|
||||
}
|
||||
if common.DataExportEnabled {
|
||||
LogQuotaData(userId, username, modelName, quota, common.GetTimestamp())
|
||||
go LogQuotaData(userId, username, modelName, quota, common.GetTimestamp())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,9 +37,7 @@ func UpdateQuotaData() {
|
||||
var CacheQuotaData = make(map[string]*QuotaData)
|
||||
var CacheQuotaDataLock = sync.Mutex{}
|
||||
|
||||
func LogQuotaDataCache(userId int, username string, modelName string, quota int, createdAt int64) {
|
||||
// 只精确到小时
|
||||
createdAt = createdAt - (createdAt % 3600)
|
||||
func logQuotaDataCache(userId int, username string, modelName string, quota int, createdAt int64) {
|
||||
key := fmt.Sprintf("%d-%s-%s-%d", userId, username, modelName, createdAt)
|
||||
quotaData, ok := CacheQuotaData[key]
|
||||
if ok {
|
||||
@ -59,9 +57,12 @@ func LogQuotaDataCache(userId int, username string, modelName string, quota int,
|
||||
}
|
||||
|
||||
func LogQuotaData(userId int, username string, modelName string, quota int, createdAt int64) {
|
||||
// 只精确到小时
|
||||
createdAt = createdAt - (createdAt % 3600)
|
||||
|
||||
CacheQuotaDataLock.Lock()
|
||||
defer CacheQuotaDataLock.Unlock()
|
||||
LogQuotaDataCache(userId, username, modelName, quota, createdAt)
|
||||
logQuotaDataCache(userId, username, modelName, quota, createdAt)
|
||||
}
|
||||
|
||||
func SaveQuotaDataCache() {
|
||||
|
Loading…
Reference in New Issue
Block a user