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
aca1a556
authored
Jan 07, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 索引名称长度
parent
d9107379
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
model/usedata.go
+11
-3
No files found.
model/usedata.go
View file @
aca1a556
...
@@ -3,6 +3,7 @@ package model
...
@@ -3,6 +3,7 @@ package model
import
(
import
(
"fmt"
"fmt"
"one-api/common"
"one-api/common"
"sync"
"time"
"time"
)
)
...
@@ -10,9 +11,9 @@ import (
...
@@ -10,9 +11,9 @@ import (
type
QuotaData
struct
{
type
QuotaData
struct
{
Id
int
`json:"id"`
Id
int
`json:"id"`
UserID
int
`json:"user_id" gorm:"index"`
UserID
int
`json:"user_id" gorm:"index"`
Username
string
`json:"username" gorm:"index:i
ndex_quota_data
_model_user_name,priority:2;default:''"`
Username
string
`json:"username" gorm:"index:i
dx_qdt
_model_user_name,priority:2;default:''"`
ModelName
string
`json:"model_name" gorm:"index;index:i
ndex_quota_data
_model_user_name,priority:1;default:''"`
ModelName
string
`json:"model_name" gorm:"index;index:i
dx_qdt
_model_user_name,priority:1;default:''"`
CreatedAt
int64
`json:"created_at" gorm:"bigint;index:i
ndex_quota_data
_created_at,priority:2"`
CreatedAt
int64
`json:"created_at" gorm:"bigint;index:i
dx_qdt
_created_at,priority:2"`
Count
int
`json:"count" gorm:"default:0"`
Count
int
`json:"count" gorm:"default:0"`
Quota
int
`json:"quota" gorm:"default:0"`
Quota
int
`json:"quota" gorm:"default:0"`
}
}
...
@@ -34,6 +35,7 @@ func UpdateQuotaData() {
...
@@ -34,6 +35,7 @@ func UpdateQuotaData() {
}
}
var
CacheQuotaData
=
make
(
map
[
string
]
*
QuotaData
)
var
CacheQuotaData
=
make
(
map
[
string
]
*
QuotaData
)
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
)
{
// 只精确到小时
// 只精确到小时
...
@@ -57,10 +59,15 @@ func LogQuotaDataCache(userId int, username string, modelName string, quota int,
...
@@ -57,10 +59,15 @@ 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
)
{
CacheQuotaDataLock
.
Lock
()
defer
CacheQuotaDataLock
.
Unlock
()
LogQuotaDataCache
(
userId
,
username
,
modelName
,
quota
,
createdAt
)
LogQuotaDataCache
(
userId
,
username
,
modelName
,
quota
,
createdAt
)
}
}
func
SaveQuotaDataCache
()
{
func
SaveQuotaDataCache
()
{
CacheQuotaDataLock
.
Lock
()
defer
CacheQuotaDataLock
.
Unlock
()
size
:=
len
(
CacheQuotaData
)
// 如果缓存中有数据,就保存到数据库中
// 如果缓存中有数据,就保存到数据库中
// 1. 先查询数据库中是否有数据
// 1. 先查询数据库中是否有数据
// 2. 如果有数据,就更新数据
// 2. 如果有数据,就更新数据
...
@@ -78,6 +85,7 @@ func SaveQuotaDataCache() {
...
@@ -78,6 +85,7 @@ func SaveQuotaDataCache() {
}
}
}
}
CacheQuotaData
=
make
(
map
[
string
]
*
QuotaData
)
CacheQuotaData
=
make
(
map
[
string
]
*
QuotaData
)
common
.
SysLog
(
fmt
.
Sprintf
(
"保存数据看板数据成功,共保存%d条数据"
,
size
))
}
}
func
GetQuotaDataByUsername
(
username
string
,
startTime
int64
,
endTime
int64
)
(
quotaData
[]
*
QuotaData
,
err
error
)
{
func
GetQuotaDataByUsername
(
username
string
,
startTime
int64
,
endTime
int64
)
(
quotaData
[]
*
QuotaData
,
err
error
)
{
...
...
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