mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-01-18 18:04:27 -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) {
|
||||
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}
|
||||
}),
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue