diff --git a/nsqlookupd/http.go b/nsqlookupd/http.go index 22bea8831..c9fa2e1a7 100644 --- a/nsqlookupd/http.go +++ b/nsqlookupd/http.go @@ -265,6 +265,7 @@ func (s *httpServer) doNodes(w http.ResponseWriter, req *http.Request, ps httpro producers := s.ctx.nsqlookupd.DB.FindProducers("client", "", "").FilterByActive( s.ctx.nsqlookupd.opts.InactiveProducerTimeout, 0) nodes := make([]*node, len(producers)) + topicProducersMap := make(map[string]Producers) for i, p := range producers { topics := s.ctx.nsqlookupd.DB.LookupRegistrations(p.peerInfo.id).Filter("topic", "*", "").Keys() @@ -272,10 +273,15 @@ func (s *httpServer) doNodes(w http.ResponseWriter, req *http.Request, ps httpro // to add tombstone information tombstones := make([]bool, len(topics)) for j, t := range topics { - topicProducers := s.ctx.nsqlookupd.DB.FindProducers("topic", t, "") + if _, exists := topicProducersMap[t]; !exists { + topicProducersMap[t] = s.ctx.nsqlookupd.DB.FindProducers("topic", t, "") + } + + topicProducers := topicProducersMap[t] for _, tp := range topicProducers { if tp.peerInfo == p.peerInfo { tombstones[j] = tp.IsTombstoned(s.ctx.nsqlookupd.opts.TombstoneLifetime) + break } } } diff --git a/nsqlookupd/registration_db.go b/nsqlookupd/registration_db.go index 7b6bd32e9..ba1d1d09c 100644 --- a/nsqlookupd/registration_db.go +++ b/nsqlookupd/registration_db.go @@ -141,7 +141,8 @@ func (r *RegistrationDB) FindProducers(category string, key string, subkey strin return ProducerMap2Slice(r.registrationMap[k]) } - results := make(map[string]*Producer) + results := make(map[string]struct{}) + var retProducers Producers for k, producers := range r.registrationMap { if !k.IsMatch(category, key, subkey) { continue @@ -149,11 +150,12 @@ func (r *RegistrationDB) FindProducers(category string, key string, subkey strin for _, producer := range producers { _, found := results[producer.peerInfo.id] if found == false { - results[producer.peerInfo.id] = producer + results[producer.peerInfo.id] = struct{}{} + retProducers = append(retProducers, producer) } } } - return ProducerMap2Slice(results) + return retProducers } func (r *RegistrationDB) LookupRegistrations(id string) Registrations {