mirror of https://github.com/halo-dev/halo
fix: failed to build due to wrong type (#2712)
#### What type of PR is this? /kind bug /area core /milestone 2.0 #### What this PR does / why we need it: 修复上一个 PR 没有拉取最新代码合并后导致无法构建的问题 #### Special notes for your reviewer: /cc @halo-dev/sig-halo #### Does this PR introduce a user-facing change? ```release-note None ```pull/2715/head
parent
9f53cd1123
commit
9e5c6a45c9
|
@ -2,14 +2,13 @@ package run.halo.app.search;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import reactor.core.Exceptions;
|
import reactor.core.Exceptions;
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.core.scheduler.Schedulers;
|
|
||||||
import run.halo.app.core.extension.Post;
|
import run.halo.app.core.extension.Post;
|
||||||
import run.halo.app.plugin.extensionpoint.ExtensionGetter;
|
import run.halo.app.plugin.extensionpoint.ExtensionGetter;
|
||||||
import run.halo.app.search.post.PostDoc;
|
import run.halo.app.search.post.PostDoc;
|
||||||
import run.halo.app.search.post.PostSearchService;
|
import run.halo.app.search.post.PostSearchService;
|
||||||
import run.halo.app.theme.finders.PostFinder;
|
import run.halo.app.theme.finders.PostFinder;
|
||||||
|
import run.halo.app.theme.finders.vo.PostVo;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class IndicesServiceImpl implements IndicesService {
|
public class IndicesServiceImpl implements IndicesService {
|
||||||
|
@ -25,13 +24,18 @@ public class IndicesServiceImpl implements IndicesService {
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> rebuildPostIndices() {
|
public Mono<Void> rebuildPostIndices() {
|
||||||
return extensionGetter.getEnabledExtension(PostSearchService.class)
|
return extensionGetter.getEnabledExtension(PostSearchService.class)
|
||||||
// TODO Optimize listing posts with non-blocking.
|
.flatMap(searchService -> postFinder.listAll()
|
||||||
.flatMap(searchService -> Flux.fromStream(() -> postFinder.list(0, 0)
|
|
||||||
.stream()
|
|
||||||
.filter(post -> Post.isPublished(post.getMetadata()))
|
.filter(post -> Post.isPublished(post.getMetadata()))
|
||||||
.peek(post -> postFinder.content(post.getMetadata().getName()))
|
.flatMap(listedPostVo -> {
|
||||||
.map(PostDoc::from))
|
PostVo postVo = PostVo.from(listedPostVo);
|
||||||
.subscribeOn(Schedulers.boundedElastic())
|
return postFinder.content(postVo.getMetadata().getName())
|
||||||
|
.map(content -> {
|
||||||
|
postVo.setContent(content);
|
||||||
|
return postVo;
|
||||||
|
})
|
||||||
|
.defaultIfEmpty(postVo);
|
||||||
|
})
|
||||||
|
.map(PostDoc::from)
|
||||||
.limitRate(100)
|
.limitRate(100)
|
||||||
.buffer(100)
|
.buffer(100)
|
||||||
.doOnNext(postDocs -> {
|
.doOnNext(postDocs -> {
|
||||||
|
|
|
@ -29,11 +29,10 @@ public class PostEventListener {
|
||||||
@Async
|
@Async
|
||||||
@EventListener(PostPublishedEvent.class)
|
@EventListener(PostPublishedEvent.class)
|
||||||
public void handlePostPublished(PostPublishedEvent publishedEvent) throws InterruptedException {
|
public void handlePostPublished(PostPublishedEvent publishedEvent) throws InterruptedException {
|
||||||
var postVo = postFinder.getByName(publishedEvent.getPostName());
|
|
||||||
var postDoc = PostDoc.from(postVo);
|
|
||||||
|
|
||||||
var latch = new CountDownLatch(1);
|
var latch = new CountDownLatch(1);
|
||||||
extensionGetter.getEnabledExtension(PostSearchService.class)
|
postFinder.getByName(publishedEvent.getPostName())
|
||||||
|
.map(PostDoc::from)
|
||||||
|
.flatMap(postDoc -> extensionGetter.getEnabledExtension(PostSearchService.class)
|
||||||
.doOnNext(searchService -> {
|
.doOnNext(searchService -> {
|
||||||
try {
|
try {
|
||||||
searchService.addDocuments(List.of(postDoc));
|
searchService.addDocuments(List.of(postDoc));
|
||||||
|
@ -41,6 +40,7 @@ public class PostEventListener {
|
||||||
throw Exceptions.propagate(e);
|
throw Exceptions.propagate(e);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
)
|
||||||
.doFinally(signalType -> latch.countDown())
|
.doFinally(signalType -> latch.countDown())
|
||||||
.subscribe();
|
.subscribe();
|
||||||
latch.await();
|
latch.await();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package run.halo.app.theme.finders;
|
package run.halo.app.theme.finders;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import run.halo.app.core.extension.Post;
|
import run.halo.app.core.extension.Post;
|
||||||
import run.halo.app.extension.ListResult;
|
import run.halo.app.extension.ListResult;
|
||||||
|
@ -24,6 +25,8 @@ public interface PostFinder {
|
||||||
|
|
||||||
Mono<NavigationPostVo> cursor(String current);
|
Mono<NavigationPostVo> cursor(String current);
|
||||||
|
|
||||||
|
Flux<ListedPostVo> listAll();
|
||||||
|
|
||||||
Mono<ListResult<ListedPostVo>> list(@Nullable Integer page, @Nullable Integer size);
|
Mono<ListResult<ListedPostVo>> list(@Nullable Integer page, @Nullable Integer size);
|
||||||
|
|
||||||
Mono<ListResult<ListedPostVo>> listByCategory(@Nullable Integer page, @Nullable Integer size,
|
Mono<ListResult<ListedPostVo>> listByCategory(@Nullable Integer page, @Nullable Integer size,
|
||||||
|
|
|
@ -124,6 +124,12 @@ public class PostFinderImpl implements PostFinder {
|
||||||
.defaultIfEmpty(NavigationPostVo.empty());
|
.defaultIfEmpty(NavigationPostVo.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<ListedPostVo> listAll() {
|
||||||
|
return client.list(Post.class, FIXED_PREDICATE, defaultComparator())
|
||||||
|
.flatMap(this::getListedPostVo);
|
||||||
|
}
|
||||||
|
|
||||||
static Pair<String, String> postPreviousNextPair(List<String> postNames,
|
static Pair<String, String> postPreviousNextPair(List<String> postNames,
|
||||||
String currentName) {
|
String currentName) {
|
||||||
FixedSizeSlidingWindow<String> window = new FixedSizeSlidingWindow<>(3);
|
FixedSizeSlidingWindow<String> window = new FixedSizeSlidingWindow<>(3);
|
||||||
|
|
Loading…
Reference in New Issue