mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-01-31 08:04:28 -06:00
Don't double-cache key results
This commit is contained in:
parent
0e1a9713f1
commit
1ff04e2461
|
@ -14,28 +14,16 @@ import (
|
||||||
func (s *ServerKeyAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
func (s *ServerKeyAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
||||||
internalAPIMux.Handle(api.ServerKeyQueryPublicKeyPath,
|
internalAPIMux.Handle(api.ServerKeyQueryPublicKeyPath,
|
||||||
internal.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {
|
internal.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {
|
||||||
result := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{}
|
|
||||||
request := api.QueryPublicKeysRequest{}
|
request := api.QueryPublicKeysRequest{}
|
||||||
response := api.QueryPublicKeysResponse{}
|
response := api.QueryPublicKeysResponse{}
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
lookup := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp)
|
keys, err := s.FetchKeys(req.Context(), request.Requests)
|
||||||
for req, timestamp := range request.Requests {
|
|
||||||
if res, ok := s.ImmutableCache.GetServerKey(req); ok {
|
|
||||||
result[req] = res
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
lookup[req] = timestamp
|
|
||||||
}
|
|
||||||
keys, err := s.FetchKeys(req.Context(), lookup)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
for req, res := range keys {
|
response.Results = keys
|
||||||
result[req] = res
|
|
||||||
}
|
|
||||||
response.Results = result
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue