diff --git a/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java b/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java index 81e2a352d..bc91c385e 100644 --- a/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java +++ b/src/main/java/run/halo/app/content/impl/SinglePageServiceImpl.java @@ -140,32 +140,38 @@ public class SinglePageServiceImpl implements SinglePageService { private Mono getListedSinglePage(SinglePage singlePage) { Assert.notNull(singlePage, "The singlePage must not be null."); - ListedSinglePage listedSinglePage = new ListedSinglePage(); - listedSinglePage.setPage(singlePage); - return Mono.just(listedSinglePage) - .flatMap(page -> listContributors(singlePage.getStatusOrDefault().getContributors()) - .map(contributors -> { - page.setContributors(contributors); - return page; - })); + return Mono.just(singlePage) + .map(sp -> { + ListedSinglePage listedSinglePage = new ListedSinglePage(); + listedSinglePage.setPage(singlePage); + return listedSinglePage; + }) + .flatMap(lsp -> + setContributors(singlePage.getStatusOrDefault().getContributors(), lsp)); } - private Mono> listContributors(List usernames) { + private Mono setContributors(List usernames, + ListedSinglePage singlePage) { + return listContributors(usernames) + .collectList() + .doOnNext(singlePage::setContributors) + .map(contributors -> singlePage) + .defaultIfEmpty(singlePage); + } + + private Flux listContributors(List usernames) { if (usernames == null) { - return Mono.empty(); + return Flux.empty(); } return Flux.fromIterable(usernames) - .map(username -> client.fetch(User.class, username) - .map(user -> { - Contributor contributor = new Contributor(); - contributor.setName(username); - contributor.setDisplayName(user.getSpec().getDisplayName()); - contributor.setAvatar(user.getSpec().getAvatar()); - return contributor; - }) - ) - .flatMap(Function.identity()) - .collectList(); + .flatMap(username -> client.fetch(User.class, username)) + .map(user -> { + Contributor contributor = new Contributor(); + contributor.setName(user.getMetadata().getName()); + contributor.setDisplayName(user.getSpec().getDisplayName()); + contributor.setAvatar(user.getSpec().getAvatar()); + return contributor; + }); } boolean contains(Collection left, List right) { diff --git a/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java b/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java index 9e8efc6de..e40e41626 100644 --- a/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java +++ b/src/main/java/run/halo/app/core/extension/reconciler/SinglePageReconciler.java @@ -172,7 +172,8 @@ public class SinglePageReconciler implements Reconciler { if (excerpt.getAutoGenerate()) { contentService.getContent(spec.getHeadSnapshot()) - .subscribe(content -> { + .blockOptional() + .ifPresent(content -> { String contentRevised = content.content(); status.setExcerpt(getExcerpt(contentRevised)); }); @@ -184,7 +185,7 @@ public class SinglePageReconciler implements Reconciler { String headSnapshot = singlePage.getSpec().getHeadSnapshot(); contentService.listSnapshots(Snapshot.SubjectRef.of(SinglePage.KIND, name)) .collectList() - .subscribe(snapshots -> { + .blockOptional().ifPresent(snapshots -> { List contributors = snapshots.stream() .map(snapshot -> { Set usernames = snapshot.getSpec().getContributors();