From d53daadb3b549b86373af728d8242bca857daace Mon Sep 17 00:00:00 2001 From: Przemek Delewski Date: Sat, 21 Dec 2024 21:46:06 +0100 Subject: [PATCH] Fixing newHandlers population --- quesma/quesma/dual_write_proxy_v2.go | 3 --- quesma/v2/core/mux.go | 16 +++++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/quesma/quesma/dual_write_proxy_v2.go b/quesma/quesma/dual_write_proxy_v2.go index 547660f13..ffcce21a2 100644 --- a/quesma/quesma/dual_write_proxy_v2.go +++ b/quesma/quesma/dual_write_proxy_v2.go @@ -90,9 +90,6 @@ func newDualWriteProxyV2(dependencies quesma_api.Dependencies, schemaLoader clic queryPipeline := quesma_api.NewPipeline() queryPipeline.AddFrontendConnector(elasticHttpQueryFrontendConnector) - // TODO the order of pipelines is important - // that's due current bug/limitation in quesma.Build() method - // listener in the case of the same tcp port has to be shared quesmaBuilder.AddPipeline(queryPipeline) quesmaBuilder.AddPipeline(ingestPipeline) diff --git a/quesma/v2/core/mux.go b/quesma/v2/core/mux.go index 51a2742c9..02b49deec 100644 --- a/quesma/v2/core/mux.go +++ b/quesma/v2/core/mux.go @@ -206,14 +206,20 @@ func (p *PathRouter) GetHandlers() map[string]HandlersPipe { func (p *PathRouter) SetHandlers(handlers map[string]HandlersPipe) { newHandlers := make(map[string]HandlersPipe, 0) for path, handler := range handlers { - for index := range p.mappings { + var index int + var found bool + for index = range p.mappings { if p.mappings[index].pattern == path { - p.mappings[index].handler.Processors = handler.Processors - p.mappings[index].handler.Predicate = handler.Predicate - } else { - newHandlers[path] = handler + found = true + break } } + if found { + p.mappings[index].handler.Processors = handler.Processors + p.mappings[index].handler.Predicate = handler.Predicate + } else { + newHandlers[path] = handler + } } for path, handler := range newHandlers { p.mappings = append(p.mappings, mapping{pattern: path,