memory leak

This commit is contained in:
2026-02-05 15:14:47 +03:00
parent b894cbd9c3
commit 0fded455b8
22 changed files with 420 additions and 170 deletions

35
database/mdb/ai_chats.go Normal file
View File

@@ -0,0 +1,35 @@
package mdb
import (
"context"
"kurumibot/database"
"time"
"git.nix13.pw/scuroneko/laniakea"
"go.mongodb.org/mongo-driver/v2/bson"
)
func GetGptChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*AiChatMessage, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "gpt_chat_messages")
cursor, err := col.Find(ctx, bson.M{"chatId": chatId})
if err != nil {
return nil, err
}
result := make([]*AiChatMessage, 0)
err = cursor.All(ctx, &result)
return result, err
}
func UpdateGptChatHistory(db *laniakea.DatabaseContext, chatId, role, message string) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "gpt_chat_messages")
_, err := col.InsertOne(ctx, AiChatMessage{
bson.NewObjectID(),
chatId,
role,
message, 0,
})
return err
}