From 3516e101ddc1174ffa86eb33956835e45d6f3170 Mon Sep 17 00:00:00 2001 From: Maximilian Wittenburg Date: Thu, 21 Mar 2024 14:59:51 +0100 Subject: [PATCH] remove db index --- src/database/client.go | 26 +++++++++++++------------- src/server/server.go | 5 +++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/database/client.go b/src/database/client.go index b3766da..60b1adb 100644 --- a/src/database/client.go +++ b/src/database/client.go @@ -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 } diff --git a/src/server/server.go b/src/server/server.go index e9bc354..b584009 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -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) @@ -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 }