Skip to content

Commit

Permalink
remove db index
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxW1337 committed Mar 21, 2024
1 parent 23fc18d commit 3516e10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/database/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ func (d DatabaseClientImpl) CreateMatch(ctx context.Context, entry *Match) (stri
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()

// TTL index
index := mongo.IndexModel{
Keys: bson.D{{"created_at", 1}},
Options: options.Index().SetExpireAfterSeconds(int32(d.matchExpirationTTL.Seconds())),
}

_, err := d.collection.Indexes().CreateOne(ctx, index)
if err != nil {
// TODO: recreate index if already existing
slog.Error("Error creating index", "Error", err)
}

err = d.collection.CreateWithCtx(ctx, entry)
//// TTL index
//index := mongo.IndexModel{
// Keys: bson.D{{"created_at", 1}},
// Options: options.Index().SetExpireAfterSeconds(int32(d.matchExpirationTTL.Seconds())),
//}
//
//_, err := d.collection.Indexes().CreateOne(ctx, index)
//if err != nil {
// // TODO: recreate index if already existing
// slog.Error("Error creating index", "Error", err)
//}

err := d.collection.CreateWithCtx(ctx, entry)

return entry.ID.String(), err
}
Expand Down
5 changes: 5 additions & 0 deletions src/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (s *Server) webhookHandler(ctx *gin.Context) {
defer body.Close()

var webhookPayload interface{}

err := json.NewDecoder(body).Decode(&webhookPayload)
if err != nil {
slog.Error("Error decoding webhook payload", "error", err)
Expand Down Expand Up @@ -251,15 +252,19 @@ func (s *Server) testTemplateHandler(ctx *gin.Context) {

parsedTmt2MatchTemplate, err := template.ParseTemplateForMatch(templateTextToTest, &testMatch)
if err != nil {
slog.Error("Error parsing template", "error", err)
ctx.JSON(400, gin.H{"error": err.Error()})
return
}

slog.Debug("Parsed template", "parsedTmt2MatchTemplate", parsedTmt2MatchTemplate)

// try to bind parsed template to tmt2 match

var createMatchDto = tmt2_go.IMatchCreateDto{}
err = json.Unmarshal([]byte(parsedTmt2MatchTemplate), &createMatchDto)
if err != nil {
slog.Error("Error unmarshalling parsed template", "error", err)
ctx.JSON(400, gin.H{"error": err.Error()})
return
}
Expand Down

0 comments on commit 3516e10

Please sign in to comment.