Don't double-cache key results

This commit is contained in:
Neil Alexander 2020-06-04 14:13:28 +01:00
parent 0e1a9713f1
commit 1ff04e2461

View file

@ -14,28 +14,16 @@ import (
func (s *ServerKeyAPI) SetupHTTP(internalAPIMux *mux.Router) {
internalAPIMux.Handle(api.ServerKeyQueryPublicKeyPath,
internal.MakeInternalAPI("queryPublicKeys", func(req *http.Request) util.JSONResponse {
result := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{}
request := api.QueryPublicKeysRequest{}
response := api.QueryPublicKeysResponse{}
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
lookup := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp)
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)
keys, err := s.FetchKeys(req.Context(), request.Requests)
if err != nil {
return util.ErrorResponse(err)
}
for req, res := range keys {
result[req] = res
}
response.Results = result
response.Results = keys
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)