#977 - Performance improvements in link generation.

Introduced more caches for reusable value objects: UriTemplate, MethodParameters. Cache UriTemplate.toString() to avoid re-computation. Avoid recomputing the affordances if possible in WebHandler. Removed cache in AnnotatedParametersParameterAccessor as that one now transitively benefits from the one introduced in MethodParameters.

Related ticket: spring-projects/spring-framework#22730.
This commit is contained in:
Oliver Drotbohm
2019-04-03 18:31:46 +02:00
parent fc3767b90b
commit 39404ea2d9
15 changed files with 152 additions and 137 deletions

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.hateoas.client;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.*;
import lombok.RequiredArgsConstructor;
import lombok.Value;
@@ -385,15 +385,14 @@ public class Traverson {
UriStringAndHeaders uriAndHeaders = getAndFindLinkWithRel(baseUri.toString(), rels.iterator(), HttpHeaders.EMPTY);
return new UriStringAndHeaders(new UriTemplate(uriAndHeaders.getUri()).toString(),
uriAndHeaders.getHttpHeaders());
return new UriStringAndHeaders(UriTemplate.of(uriAndHeaders.getUri()).toString(), uriAndHeaders.getHttpHeaders());
}
private URIAndHeaders traverseToExpandedFinalUrl() {
UriStringAndHeaders uriAndHeaders = getAndFindLinkWithRel(baseUri.toString(), rels.iterator(), HttpHeaders.EMPTY);
return new URIAndHeaders(new UriTemplate(uriAndHeaders.getUri()).expand(templateParameters),
return new URIAndHeaders(UriTemplate.of(uriAndHeaders.getUri()).expand(templateParameters),
uriAndHeaders.getHttpHeaders());
}
@@ -404,7 +403,7 @@ public class Traverson {
}
HttpEntity<?> request = prepareRequest(mergeHeaders(this.headers, extraHeaders));
URI target = new UriTemplate(uri).expand();
URI target = UriTemplate.of(uri).expand();
ResponseEntity<String> responseEntity = operations.exchange(target, GET, request, String.class);
MediaType contentType = responseEntity.getHeaders().getContentType();