mirror of https://github.com/halo-dev/halo
Remove wrong cache of pattern matchers
parent
18105cbe44
commit
b4ac91df20
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
@ -99,11 +98,6 @@ public class ThemeCompositeRouterFunction
|
|||
this.cachedRouters = routerFunctions();
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onApplicationStarted(ApplicationReadyEvent event) {
|
||||
this.cachedRouters = routerFunctions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (running) {
|
||||
|
|
|
@ -6,14 +6,10 @@ import static org.springframework.web.reactive.function.server.RequestPredicates
|
|||
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
|
||||
import static run.halo.app.content.permalinks.PostPermalinkPolicy.DEFAULT_CATEGORY;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -241,9 +237,6 @@ public class PostRouteFactory implements RouteFactory {
|
|||
@Getter
|
||||
static class PatternParser {
|
||||
private static final Pattern PATTERN_COMPILE = Pattern.compile("([^&?]*)=\\{(.*?)\\}(&|$)");
|
||||
private static final Cache<String, Matcher> MATCHER_CACHE = CacheBuilder.newBuilder()
|
||||
.maximumSize(5)
|
||||
.build();
|
||||
|
||||
private final String pattern;
|
||||
private String paramName;
|
||||
|
@ -252,7 +245,7 @@ public class PostRouteFactory implements RouteFactory {
|
|||
|
||||
PatternParser(String pattern) {
|
||||
this.pattern = pattern;
|
||||
Matcher matcher = patternToMatcher(pattern);
|
||||
var matcher = PATTERN_COMPILE.matcher(pattern);
|
||||
if (matcher.find()) {
|
||||
this.paramName = matcher.group(1);
|
||||
this.placeholderName = matcher.group(2);
|
||||
|
@ -262,14 +255,6 @@ public class PostRouteFactory implements RouteFactory {
|
|||
}
|
||||
}
|
||||
|
||||
Matcher patternToMatcher(String pattern) {
|
||||
try {
|
||||
return MATCHER_CACHE.get(pattern, () -> PATTERN_COMPILE.matcher(pattern));
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
RequestPredicate toRequestPredicate() {
|
||||
if (!this.isQueryParamPattern) {
|
||||
throw new IllegalStateException("Not a query param pattern: " + pattern);
|
||||
|
|
|
@ -7,6 +7,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
|
@ -66,6 +67,14 @@ class PostRouteFactoryTest extends RouteFactoryTestSuite {
|
|||
@InjectMocks
|
||||
private PostRouteFactory postRouteFactory;
|
||||
|
||||
@Test
|
||||
void shouldBeSameResultWhenParsePattenMultiply() {
|
||||
var parser = new PostRouteFactory.PatternParser("/?p={slug}");
|
||||
Assertions.assertTrue(parser.isQueryParamPattern());
|
||||
parser = new PostRouteFactory.PatternParser("/?p={slug}");
|
||||
Assertions.assertTrue(parser.isQueryParamPattern());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create() {
|
||||
Post post = TestPost.postV1();
|
||||
|
|
Loading…
Reference in New Issue