|
|
@@ -3,11 +3,12 @@ package model
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
- "github.com/bytedance/gopkg/util/gopool"
|
|
|
- "gorm.io/gorm"
|
|
|
"one-api/common"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/bytedance/gopkg/util/gopool"
|
|
|
+ "gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
type Log struct {
|
|
|
@@ -95,7 +96,7 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, startIdx int, num int, channel int) (logs []*Log, err error) {
|
|
|
+func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string, startIdx int, num int, channel int) (logs []*Log, total int64, err error) {
|
|
|
var tx *gorm.DB
|
|
|
if logType == LogTypeUnknown {
|
|
|
tx = DB
|
|
|
@@ -120,8 +121,15 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
|
|
|
if channel != 0 {
|
|
|
tx = tx.Where("channel_id = ?", channel)
|
|
|
}
|
|
|
+ err = tx.Model(&Log{}).Count(&total).Error
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
err = tx.Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error
|
|
|
- return logs, err
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ return logs, total, err
|
|
|
}
|
|
|
|
|
|
func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int64, modelName string, tokenName string, startIdx int, num int) (logs []*Log, err error) {
|