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
John Niang 2022-09-27 17:46:15 +08:00 committed by GitHub
parent 1fc37673f7
commit 11d91712f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 23 deletions

View File

@ -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) {

View File

@ -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();