PT #164216122: JDT LS search performance improvement 2
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -14,11 +14,12 @@ import java.time.Duration;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry.ValueProviderStrategy;
|
||||
import org.springframework.ide.vscode.boot.metadata.hints.StsValueHint;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
@@ -52,6 +53,8 @@ import reactor.util.function.Tuples;
|
||||
*/
|
||||
public abstract class CachingValueProvider implements ValueProviderStrategy {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CachingValueProvider.class);
|
||||
|
||||
private static final Duration DEFAULT_TIMEOUT = Duration.ofMillis(1000);
|
||||
|
||||
/**
|
||||
@@ -76,6 +79,8 @@ public abstract class CachingValueProvider implements ValueProviderStrategy {
|
||||
|
||||
public CacheEntry(String query, Flux<StsValueHint> producer) {
|
||||
values = producer
|
||||
.doOnNext(t -> count++)
|
||||
.doOnComplete(() -> isComplete = true)
|
||||
.take(MAX_RESULTS)
|
||||
.cache(MAX_RESULTS);
|
||||
values.subscribe(); // create infinite demand so that we actually force cache entries to be fetched upto the max.
|
||||
@@ -95,7 +100,7 @@ public abstract class CachingValueProvider implements ValueProviderStrategy {
|
||||
try {
|
||||
cached = cache.get(key, () -> new CacheEntry(query, getValuesIncremental(javaProject, query)));
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
log.error("{}", e);
|
||||
}
|
||||
return cached.values;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import reactor.util.function.Tuples;
|
||||
* @author Kris De Volder
|
||||
* @author Alex Boyko
|
||||
*/
|
||||
public class LoggerNameProvider extends CachingValueProvider {
|
||||
public class LoggerNameProvider implements ValueProviderStrategy {
|
||||
|
||||
private static final String LOGGING_GROUPS_PREFIX = "logging.group.";
|
||||
private final ProjectBasedPropertyIndexProvider adhocProperties;
|
||||
@@ -56,6 +56,11 @@ public class LoggerNameProvider extends CachingValueProvider {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<StsValueHint> getValues(IJavaProject javaProject, String query) {
|
||||
return getValuesAsync(javaProject, query);
|
||||
}
|
||||
|
||||
Collection<String> loggerGroupNames(IJavaProject jp) {
|
||||
Builder<String> builder = ImmutableSet.builder();
|
||||
if (adhocProperties!=null && includeGroups) {
|
||||
@@ -75,8 +80,7 @@ public class LoggerNameProvider extends CachingValueProvider {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Flux<StsValueHint> getValuesAsync(IJavaProject javaProject, String query) {
|
||||
private Flux<StsValueHint> getValuesAsync(IJavaProject javaProject, String query) {
|
||||
return Flux.concat(
|
||||
Flux.fromIterable(loggerGroupNames(javaProject))
|
||||
.map(loggerName -> Tuples.of(StsValueHint.create(loggerName), FuzzyMatcher.matchScore(query, loggerName)))
|
||||
|
||||
@@ -105,7 +105,7 @@ public class LoggerNameProviderTest {
|
||||
public void incrementalResults() throws Exception {
|
||||
String fullQuery = "jboss";
|
||||
|
||||
CachingValueProvider p = create();
|
||||
LoggerNameProvider p = create();
|
||||
for (int i = 0; i <= fullQuery.length(); i++) {
|
||||
String query = fullQuery.substring(0, i);
|
||||
List<String> results = getResults(p, query);
|
||||
@@ -154,7 +154,7 @@ public class LoggerNameProviderTest {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private List<String> getResults(CachingValueProvider p, String query) {
|
||||
private List<String> getResults(LoggerNameProvider p, String query) {
|
||||
return p.getValues(project, query).toStream()
|
||||
.map((h) -> h.getValue().toString())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Reference in New Issue
Block a user