session管理时获取
This commit is contained in:
parent
f4433d8398
commit
b494c534b6
12
dao/im.go
12
dao/im.go
|
|
@ -59,6 +59,18 @@ func FindSessionByUserID(userID, sessionType int) []Session {
|
|||
return sessions
|
||||
}
|
||||
|
||||
// 获取用户最新的创建时间会话列表 100个
|
||||
func FindSessionByUserIDV2(userID int) []Session {
|
||||
var sessions []Session
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
DB.Debug().Where("user_id = ?", userID).Order("created_at DESC").Limit(100).Find(&sessions)
|
||||
} else {
|
||||
DB.Where("user_id = ?", userID).Order("created_at DESC").Limit(100).Find(&sessions)
|
||||
}
|
||||
return sessions
|
||||
|
||||
}
|
||||
|
||||
// 更新会话的名字
|
||||
func UpdateSessionByID(id int, userId int, name string, context []int) error {
|
||||
var res *gorm.DB
|
||||
|
|
|
|||
|
|
@ -20,7 +20,12 @@ func CreateSession(userID, Type int, name string) (error, uint) {
|
|||
|
||||
// 查找用户的会话列表
|
||||
func FindSessionByUserID(userID, sessionType int) []proto.SessionResponse {
|
||||
sessions := dao.FindSessionByUserID(userID, sessionType)
|
||||
var sessions []dao.Session
|
||||
if sessionType == -1 {
|
||||
sessions = dao.FindSessionByUserIDV2(userID)
|
||||
} else {
|
||||
sessions = dao.FindSessionByUserID(userID, sessionType)
|
||||
}
|
||||
sessionsMsgCounts := dao.FindSessionMessageCountByUserID(userID)
|
||||
sessionsTokens := dao.FindModelTotalTokensBySessionID(userID)
|
||||
smap := make(map[int]int)
|
||||
|
|
|
|||
Loading…
Reference in New Issue