mirror of https://github.com/halo-dev/halo
Fix empty listing of single page (#2474)
#### What type of PR is this? /kind bug /area core /milestone 2.0 #### What this PR does / why we need it: Fix empty listing of single page while using PostgreSQL. #### Does this PR introduce a user-facing change? ```release-note None ```pull/2481/head
parent
1fc37673f7
commit
11d91712f6
|
@ -140,32 +140,38 @@ public class SinglePageServiceImpl implements SinglePageService {
|
|||
|
||||
private Mono<ListedSinglePage> getListedSinglePage(SinglePage singlePage) {
|
||||
Assert.notNull(singlePage, "The singlePage must not be null.");
|
||||
return Mono.just(singlePage)
|
||||
.map(sp -> {
|
||||
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 listedSinglePage;
|
||||
})
|
||||
.flatMap(lsp ->
|
||||
setContributors(singlePage.getStatusOrDefault().getContributors(), lsp));
|
||||
}
|
||||
|
||||
private Mono<List<Contributor>> listContributors(List<String> usernames) {
|
||||
private Mono<ListedSinglePage> setContributors(List<String> usernames,
|
||||
ListedSinglePage singlePage) {
|
||||
return listContributors(usernames)
|
||||
.collectList()
|
||||
.doOnNext(singlePage::setContributors)
|
||||
.map(contributors -> singlePage)
|
||||
.defaultIfEmpty(singlePage);
|
||||
}
|
||||
|
||||
private Flux<Contributor> listContributors(List<String> usernames) {
|
||||
if (usernames == null) {
|
||||
return Mono.empty();
|
||||
return Flux.empty();
|
||||
}
|
||||
return Flux.fromIterable(usernames)
|
||||
.map(username -> client.fetch(User.class, username)
|
||||
.flatMap(username -> client.fetch(User.class, username))
|
||||
.map(user -> {
|
||||
Contributor contributor = new Contributor();
|
||||
contributor.setName(username);
|
||||
contributor.setName(user.getMetadata().getName());
|
||||
contributor.setDisplayName(user.getSpec().getDisplayName());
|
||||
contributor.setAvatar(user.getSpec().getAvatar());
|
||||
return contributor;
|
||||
})
|
||||
)
|
||||
.flatMap(Function.identity())
|
||||
.collectList();
|
||||
});
|
||||
}
|
||||
|
||||
boolean contains(Collection<String> left, List<String> right) {
|
||||
|
|
|
@ -172,7 +172,8 @@ public class SinglePageReconciler implements Reconciler<Reconciler.Request> {
|
|||
|
||||
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<Reconciler.Request> {
|
|||
String headSnapshot = singlePage.getSpec().getHeadSnapshot();
|
||||
contentService.listSnapshots(Snapshot.SubjectRef.of(SinglePage.KIND, name))
|
||||
.collectList()
|
||||
.subscribe(snapshots -> {
|
||||
.blockOptional().ifPresent(snapshots -> {
|
||||
List<String> contributors = snapshots.stream()
|
||||
.map(snapshot -> {
|
||||
Set<String> usernames = snapshot.getSpec().getContributors();
|
||||
|
|
Loading…
Reference in New Issue