many changes; using dev laniakea

This commit is contained in:
2026-03-06 14:36:06 +03:00
parent 3ceffa23ae
commit f3f15dad78
13 changed files with 134 additions and 86 deletions

View File

@@ -7,6 +7,7 @@ import (
"git.nix13.pw/scuroneko/extypes"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
@@ -32,15 +33,17 @@ func GetConsoleLogs(db *database.Context) ([]ConsoleLogEntry, error) {
col := database.GetMongoCollection(db, "logs")
opts := options.Find()
opts.SetLimit(5)
opts.SetSort(bson.D{{"_id", 1}})
opts.SetSort(bson.D{{Key: "_id", Value: 1}})
cursor, err := col.Find(ctx, bson.D{}, opts)
if err != nil {
return nil, err
}
defer cursor.Close(ctx)
defer func(cursor *mongo.Cursor, ctx context.Context) {
_ = cursor.Close(ctx)
}(cursor, ctx)
result := make([]ConsoleLogEntry, 0)
err = cursor.All(ctx, &result)
return result, nil
return result, err
}
type MessageLogEntry struct {
@@ -64,13 +67,15 @@ func GetMessageLogs(db *database.Context) (extypes.Slice[*MessageLogEntry], erro
col := database.GetMongoCollection(db, "msg_logs")
opts := options.Find()
opts.SetLimit(5)
opts.SetSort(bson.D{{"_id", 1}})
opts.SetSort(bson.D{{Key: "_id", Value: 1}})
cursor, err := col.Find(ctx, bson.D{}, opts)
if err != nil {
return nil, err
}
defer cursor.Close(ctx)
defer func(cursor *mongo.Cursor, ctx context.Context) {
_ = cursor.Close(ctx)
}(cursor, ctx)
result := make(extypes.Slice[*MessageLogEntry], 0)
err = cursor.All(ctx, &result)
return result, nil
return result, err
}