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
45073b3b
authored
Apr 10, 2025
by
wzxjohn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: improve log delete api
parent
4f123cf9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
controller/log.go
+1
-1
model/log.go
+22
-3
No files found.
controller/log.go
View file @
45073b3b
...
@@ -196,7 +196,7 @@ func DeleteHistoryLogs(c *gin.Context) {
...
@@ -196,7 +196,7 @@ func DeleteHistoryLogs(c *gin.Context) {
})
})
return
return
}
}
count
,
err
:=
model
.
DeleteOldLog
(
targetTimestamp
)
count
,
err
:=
model
.
DeleteOldLog
(
c
.
Request
.
Context
(),
targetTimestamp
,
100
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
...
...
model/log.go
View file @
45073b3b
package
model
package
model
import
(
import
(
"context"
"fmt"
"fmt"
"one-api/common"
"one-api/common"
"os"
"os"
...
@@ -340,7 +341,25 @@ func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelNa
...
@@ -340,7 +341,25 @@ func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelNa
return
token
return
token
}
}
func
DeleteOldLog
(
targetTimestamp
int64
)
(
int64
,
error
)
{
func
DeleteOldLog
(
ctx
context
.
Context
,
targetTimestamp
int64
,
limit
int
)
(
int64
,
error
)
{
result
:=
LOG_DB
.
Where
(
"created_at < ?"
,
targetTimestamp
)
.
Delete
(
&
Log
{})
var
total
int64
=
0
return
result
.
RowsAffected
,
result
.
Error
for
{
if
nil
!=
ctx
.
Err
()
{
return
total
,
ctx
.
Err
()
}
result
:=
LOG_DB
.
Where
(
"created_at < ?"
,
targetTimestamp
)
.
Limit
(
limit
)
.
Delete
(
&
Log
{})
if
nil
!=
result
.
Error
{
return
total
,
result
.
Error
}
total
+=
result
.
RowsAffected
if
result
.
RowsAffected
<
int64
(
limit
)
{
break
}
}
return
total
,
nil
}
}
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