memory leak
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
type RPChatMessage struct {
|
||||
type AiChatMessage struct {
|
||||
Id bson.ObjectID `bson:"_id"`
|
||||
ChatID string `bson:"chatId"`
|
||||
Role string `bson:"role"`
|
||||
@@ -17,7 +17,7 @@ type RPChatMessage struct {
|
||||
Index int `bson:"index"`
|
||||
}
|
||||
|
||||
func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessage, error) {
|
||||
func GetRPChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*AiChatMessage, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
@@ -25,15 +25,15 @@ func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessa
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*RPChatMessage, 0)
|
||||
result := make([]*AiChatMessage, 0)
|
||||
err = cursor.All(ctx, &result)
|
||||
return result, err
|
||||
}
|
||||
func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message string, index int) error {
|
||||
func UpdateRPChatHistory(db *laniakea.DatabaseContext, chatId, role, message string, index int) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
_, err := col.InsertOne(ctx, RPChatMessage{
|
||||
_, err := col.InsertOne(ctx, AiChatMessage{
|
||||
bson.NewObjectID(),
|
||||
chatId,
|
||||
role,
|
||||
@@ -41,13 +41,13 @@ func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message strin
|
||||
})
|
||||
return err
|
||||
}
|
||||
func GetChatHistorySize(db *laniakea.DatabaseContext, chatId string) (int64, error) {
|
||||
func GetRPChatHistorySize(db *laniakea.DatabaseContext, chatId string) (int64, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
return col.CountDocuments(ctx, bson.M{"chatId": chatId})
|
||||
}
|
||||
func DeleteChatEntry(db *laniakea.DatabaseContext, entry *RPChatMessage) error {
|
||||
func DeleteRPChatEntry(db *laniakea.DatabaseContext, entry *AiChatMessage) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
|
||||
Reference in New Issue
Block a user