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
guqing 2022-11-17 16:04:21 +08:00 committed by GitHub
parent 9f53cd1123
commit 9e5c6a45c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 20 deletions

View File

@ -2,14 +2,13 @@ package run.halo.app.search;
import org.springframework.stereotype.Service;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import run.halo.app.core.extension.Post;
import run.halo.app.plugin.extensionpoint.ExtensionGetter;
import run.halo.app.search.post.PostDoc;
import run.halo.app.search.post.PostSearchService;
import run.halo.app.theme.finders.PostFinder;
import run.halo.app.theme.finders.vo.PostVo;
@Service
public class IndicesServiceImpl implements IndicesService {
@ -25,13 +24,18 @@ public class IndicesServiceImpl implements IndicesService {
@Override
public Mono<Void> rebuildPostIndices() {
return extensionGetter.getEnabledExtension(PostSearchService.class)
// TODO Optimize listing posts with non-blocking.
.flatMap(searchService -> Flux.fromStream(() -> postFinder.list(0, 0)
.stream()
.filter(post -> Post.isPublished(post.getMetadata()))
.peek(post -> postFinder.content(post.getMetadata().getName()))
.map(PostDoc::from))
.subscribeOn(Schedulers.boundedElastic())
.flatMap(searchService -> postFinder.listAll()
.filter(post -> Post.isPublished(post.getMetadata()))
.flatMap(listedPostVo -> {
PostVo postVo = PostVo.from(listedPostVo);
return postFinder.content(postVo.getMetadata().getName())
.map(content -> {
postVo.setContent(content);
return postVo;
})
.defaultIfEmpty(postVo);
})
.map(PostDoc::from)
.limitRate(100)
.buffer(100)
.doOnNext(postDocs -> {

View File

@ -29,18 +29,18 @@ public class PostEventListener {
@Async
@EventListener(PostPublishedEvent.class)
public void handlePostPublished(PostPublishedEvent publishedEvent) throws InterruptedException {
var postVo = postFinder.getByName(publishedEvent.getPostName());
var postDoc = PostDoc.from(postVo);
var latch = new CountDownLatch(1);
extensionGetter.getEnabledExtension(PostSearchService.class)
.doOnNext(searchService -> {
try {
searchService.addDocuments(List.of(postDoc));
} catch (Exception e) {
throw Exceptions.propagate(e);
}
})
postFinder.getByName(publishedEvent.getPostName())
.map(PostDoc::from)
.flatMap(postDoc -> extensionGetter.getEnabledExtension(PostSearchService.class)
.doOnNext(searchService -> {
try {
searchService.addDocuments(List.of(postDoc));
} catch (Exception e) {
throw Exceptions.propagate(e);
}
})
)
.doFinally(signalType -> latch.countDown())
.subscribe();
latch.await();

View File

@ -1,6 +1,7 @@
package run.halo.app.theme.finders;
import org.springframework.lang.Nullable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.Post;
import run.halo.app.extension.ListResult;
@ -24,6 +25,8 @@ public interface PostFinder {
Mono<NavigationPostVo> cursor(String current);
Flux<ListedPostVo> listAll();
Mono<ListResult<ListedPostVo>> list(@Nullable Integer page, @Nullable Integer size);
Mono<ListResult<ListedPostVo>> listByCategory(@Nullable Integer page, @Nullable Integer size,

View File

@ -124,6 +124,12 @@ public class PostFinderImpl implements PostFinder {
.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,
String currentName) {
FixedSizeSlidingWindow<String> window = new FixedSizeSlidingWindow<>(3);