mirror of https://github.com/status-im/go-waku.git
fix: rest get messages not returning more than 1 message (#898)
This commit is contained in:
parent
392558ec8e
commit
8122cf47a1
|
@ -549,7 +549,7 @@ var (
|
||||||
})
|
})
|
||||||
RESTRelayCacheCapacity = altsrc.NewIntFlag(&cli.IntFlag{
|
RESTRelayCacheCapacity = altsrc.NewIntFlag(&cli.IntFlag{
|
||||||
Name: "rest-relay-cache-capacity",
|
Name: "rest-relay-cache-capacity",
|
||||||
Value: 30,
|
Value: 1000,
|
||||||
Usage: "Capacity of the Relay REST API message cache",
|
Usage: "Capacity of the Relay REST API message cache",
|
||||||
Destination: &options.RESTServer.RelayCacheCapacity,
|
Destination: &options.RESTServer.RelayCacheCapacity,
|
||||||
EnvVars: []string{"WAKUNODE2_REST_RELAY_CACHE_CAPACITY"},
|
EnvVars: []string{"WAKUNODE2_REST_RELAY_CACHE_CAPACITY"},
|
||||||
|
|
|
@ -124,6 +124,11 @@ func (r *RelayService) getV1Messages(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var response []*RestWakuMessage
|
var response []*RestWakuMessage
|
||||||
|
done := false
|
||||||
|
for {
|
||||||
|
if done || len(response) > int(r.cacheCapacity) {
|
||||||
|
break
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case envelope, open := <-sub.Ch:
|
case envelope, open := <-sub.Ch:
|
||||||
if !open {
|
if !open {
|
||||||
|
@ -142,9 +147,11 @@ func (r *RelayService) getV1Messages(w http.ResponseWriter, req *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
response = append(response, message)
|
response = append(response, message)
|
||||||
}
|
}
|
||||||
|
case <-req.Context().Done():
|
||||||
|
done = true
|
||||||
default:
|
default:
|
||||||
break
|
done = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeErrOrResponse(w, nil, response)
|
writeErrOrResponse(w, nil, response)
|
||||||
|
@ -240,6 +247,11 @@ func (r *RelayService) getV1AutoMessages(w http.ResponseWriter, req *http.Reques
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var response []*RestWakuMessage
|
var response []*RestWakuMessage
|
||||||
|
done := false
|
||||||
|
for {
|
||||||
|
if done || len(response) > int(r.cacheCapacity) {
|
||||||
|
break
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case envelope := <-sub.Ch:
|
case envelope := <-sub.Ch:
|
||||||
message := &RestWakuMessage{}
|
message := &RestWakuMessage{}
|
||||||
|
@ -248,8 +260,11 @@ func (r *RelayService) getV1AutoMessages(w http.ResponseWriter, req *http.Reques
|
||||||
} else {
|
} else {
|
||||||
response = append(response, message)
|
response = append(response, message)
|
||||||
}
|
}
|
||||||
|
case <-req.Context().Done():
|
||||||
|
done = true
|
||||||
default:
|
default:
|
||||||
break
|
done = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeErrOrResponse(w, nil, response)
|
writeErrOrResponse(w, nil, response)
|
||||||
|
|
Loading…
Reference in New Issue