Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d15516d6
authored
Jan 09, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 优化数据看板性能
parent
de6fbc01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
model/log.go
+1
-1
model/usedata.go
+5
-4
No files found.
model/log.go
View file @
d15516d6
...
...
@@ -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
())
}
}
...
...
model/usedata.go
View file @
d15516d6
...
...
@@ -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
()
L
ogQuotaDataCache
(
userId
,
username
,
modelName
,
quota
,
createdAt
)
l
ogQuotaDataCache
(
userId
,
username
,
modelName
,
quota
,
createdAt
)
}
func
SaveQuotaDataCache
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment