Fixed crash insertion
This commit is contained in:
@@ -2,11 +2,10 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||||
|
"github.com/google/uuid"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
@@ -40,42 +39,39 @@ func (m *MongoCrashTable) IsArchived(ind backend.IndividualCrash) bool {
|
|||||||
|
|
||||||
func (m *MongoCrashTable) InsertCrash(ind backend.IndividualCrash) error {
|
func (m *MongoCrashTable) InsertCrash(ind backend.IndividualCrash) error {
|
||||||
first, _, _ := strings.Cut(ind.Stack, "\n")
|
first, _, _ := strings.Cut(ind.Stack, "\n")
|
||||||
findRes := m.col.FindOne(context.Background(),
|
res, err := m.col.UpdateOne(context.Background(),
|
||||||
bson.M{"error": ind.Error, "firstLine": first, //filter main report
|
bson.M{"error": ind.Error, "firstLine": first, //filter main report
|
||||||
"individual.stack": ind.Stack, "individual.platform": ind.Platform}, //filter individual
|
"individual": bson.M{"$elemMatch": bson.M{"stack": ind.Stack, "platform": ind.Platform}}}, //filter individual
|
||||||
// bson.M{"$inc": bson.M{"individual.count": 1}}, //increment count
|
bson.M{"$inc": bson.M{"individual.$.count": 1}}, //increment count
|
||||||
)
|
)
|
||||||
var out map[string]any
|
if err != nil && err != mongo.ErrNoDocuments {
|
||||||
findRes.Decode(&out)
|
return err
|
||||||
fmt.Println(out)
|
}
|
||||||
return errors.New("STUFF")
|
if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
||||||
// if err != nil && err != mongo.ErrNoDocuments {
|
ind.Count = 1
|
||||||
// return err
|
res, err = m.col.UpdateMany(context.Background(),
|
||||||
// }
|
bson.M{"error": ind.Error, "firstLine": first}, //filter
|
||||||
// if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
bson.M{"$push": bson.M{"individual": ind}}, //Add new individual report
|
||||||
// ind.Count = 1
|
)
|
||||||
// res, err = m.col.UpdateMany(context.Background(),
|
if err != nil && err != mongo.ErrNoDocuments {
|
||||||
// bson.M{"error": ind.Error, "firstLine": first}, //filter
|
return err
|
||||||
// bson.M{"$push": bson.M{"individual": ind}}, //Add new individual report
|
}
|
||||||
// )
|
if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
||||||
// if err != nil && err != mongo.ErrNoDocuments {
|
var id uuid.UUID
|
||||||
// return err
|
id, err = uuid.NewV7()
|
||||||
// }
|
if err != nil {
|
||||||
// if err == mongo.ErrNoDocuments || res.MatchedCount == 0 {
|
return err
|
||||||
// var id uuid.UUID
|
}
|
||||||
// id, err = uuid.NewV7()
|
ind.Count = 1
|
||||||
// if err != nil {
|
_, err = m.col.InsertOne(context.Background(),
|
||||||
// return err
|
backend.CrashReport{
|
||||||
// }
|
ID: id.String(),
|
||||||
// _, err = m.col.InsertOne(context.Background(),
|
Error: ind.Error,
|
||||||
// backend.CrashReport{
|
FirstLine: first,
|
||||||
// ID: id.String(),
|
Individual: []backend.IndividualCrash{ind},
|
||||||
// Error: ind.Error,
|
},
|
||||||
// FirstLine: first,
|
)
|
||||||
// Individual: []backend.IndividualCrash{ind},
|
}
|
||||||
// },
|
}
|
||||||
// )
|
return err
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return err
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user