mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-05 22:03:42 +08:00
perf: 优化数据看板性能
This commit is contained in:
@@ -79,7 +79,7 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke
|
|||||||
common.LogError(ctx, "failed to record log: "+err.Error())
|
common.LogError(ctx, "failed to record log: "+err.Error())
|
||||||
}
|
}
|
||||||
if common.DataExportEnabled {
|
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 CacheQuotaData = make(map[string]*QuotaData)
|
||||||
var CacheQuotaDataLock = sync.Mutex{}
|
var CacheQuotaDataLock = sync.Mutex{}
|
||||||
|
|
||||||
func LogQuotaDataCache(userId int, username string, modelName string, quota int, createdAt int64) {
|
func logQuotaDataCache(userId int, username string, modelName string, quota int, createdAt int64) {
|
||||||
// 只精确到小时
|
|
||||||
createdAt = createdAt - (createdAt % 3600)
|
|
||||||
key := fmt.Sprintf("%d-%s-%s-%d", userId, username, modelName, createdAt)
|
key := fmt.Sprintf("%d-%s-%s-%d", userId, username, modelName, createdAt)
|
||||||
quotaData, ok := CacheQuotaData[key]
|
quotaData, ok := CacheQuotaData[key]
|
||||||
if ok {
|
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) {
|
func LogQuotaData(userId int, username string, modelName string, quota int, createdAt int64) {
|
||||||
|
// 只精确到小时
|
||||||
|
createdAt = createdAt - (createdAt % 3600)
|
||||||
|
|
||||||
CacheQuotaDataLock.Lock()
|
CacheQuotaDataLock.Lock()
|
||||||
defer CacheQuotaDataLock.Unlock()
|
defer CacheQuotaDataLock.Unlock()
|
||||||
LogQuotaDataCache(userId, username, modelName, quota, createdAt)
|
logQuotaDataCache(userId, username, modelName, quota, createdAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveQuotaDataCache() {
|
func SaveQuotaDataCache() {
|
||||||
|
|||||||
Reference in New Issue
Block a user