From 13270648257ed65d063370517426e10e72765963 Mon Sep 17 00:00:00 2001 From: John Niang Date: Mon, 13 Nov 2023 11:40:45 +0800 Subject: [PATCH] Upgrade to Spring Boot 3.2.0-RC2 --- application/build.gradle | 2 +- .../app/content/comment/ReplyService.java | 2 +- .../impl/CommentPublicQueryServiceImpl.java | 50 +++++++++++-------- .../CommentPublicQueryServiceImplTest.java | 2 +- platform/application/build.gradle | 2 +- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/application/build.gradle b/application/build.gradle index 988b82a3cd..6297762245 100644 --- a/application/build.gradle +++ b/application/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '3.1.5' + id 'org.springframework.boot' version '3.2.0-RC2' id 'io.spring.dependency-management' version '1.1.0' id "com.gorylenko.gradle-git-properties" version "2.3.2" id "checkstyle" diff --git a/application/src/main/java/run/halo/app/content/comment/ReplyService.java b/application/src/main/java/run/halo/app/content/comment/ReplyService.java index 2010f229ee..56962e8704 100644 --- a/application/src/main/java/run/halo/app/content/comment/ReplyService.java +++ b/application/src/main/java/run/halo/app/content/comment/ReplyService.java @@ -31,7 +31,7 @@ static Comparator creationTimeAscComparator() { reply -> reply.getMetadata().getCreationTimestamp(); // ascending order by creation time // asc nulls high will be placed at the end - return Comparator.comparing(creationTime, Comparators.nullsHigh()) + return Comparator.comparing(creationTime, Comparators.nullsLow()) .thenComparing(metadataCreationTime) .thenComparing(reply -> reply.getMetadata().getName()); } diff --git a/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java b/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java index 21c56609a2..29eb383db0 100644 --- a/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java +++ b/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java @@ -1,7 +1,10 @@ package run.halo.app.theme.finders.impl; +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; + import java.security.Principal; +import java.time.Instant; import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -9,7 +12,6 @@ import java.util.function.Predicate; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.lang.Nullable; import org.springframework.security.core.context.ReactiveSecurityContextHolder; @@ -254,35 +256,41 @@ static class CommentComparator implements Comparator { public int compare(Comment c1, Comment c2) { boolean c1Top = BooleanUtils.isTrue(c1.getSpec().getTop()); boolean c2Top = BooleanUtils.isTrue(c2.getSpec().getTop()); - if (c1Top == c2Top) { - int c1Priority = ObjectUtils.defaultIfNull(c1.getSpec().getPriority(), 0); - int c2Priority = ObjectUtils.defaultIfNull(c2.getSpec().getPriority(), 0); - if (c1Top) { - // 都置顶 - return Integer.compare(c1Priority, c2Priority); - } - - // 两个评论不置顶根据 creationTime 降序排列 - return Comparator.comparing( - (Comment comment) -> comment.getSpec().getCreationTime(), - Comparators.nullsLow()) - .thenComparing((Comment comment) -> comment.getMetadata().getName()) - .compare(c2, c1); - } else if (c1Top) { - // 只有 c1 置顶,c1 排前面 + + // c1 top = true && c2 top = false + if (c1Top && !c2Top) { return -1; - } else { - // 只有c2置顶, c2排在前面 + } + + // c1 top = false && c2 top = true + if (!c1Top && c2Top) { return 1; } + // c1 top = c2 top = true || c1 top = c2 top = false + var priorityComparator = Comparator.comparing( + comment -> defaultIfNull(comment.getSpec().getPriority(), 0)); + + var creationTimeComparator = Comparator.comparing( + comment -> comment.getSpec().getCreationTime(), + Comparators.nullsLow(Comparator.reverseOrder())); + + var nameComparator = Comparator.comparing( + comment -> comment.getMetadata().getName()); + + if (c1Top) { + return priorityComparator.thenComparing(creationTimeComparator) + .thenComparing(nameComparator) + .compare(c1, c2); + } + return creationTimeComparator.thenComparing(nameComparator).compare(c1, c2); } } int pageNullSafe(Integer page) { - return ObjectUtils.defaultIfNull(page, 1); + return defaultIfNull(page, 1); } int sizeNullSafe(Integer size) { - return ObjectUtils.defaultIfNull(size, DEFAULT_SIZE); + return defaultIfNull(size, DEFAULT_SIZE); } } diff --git a/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImplTest.java b/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImplTest.java index 04b2d42a2e..c4a3eaf20f 100644 --- a/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImplTest.java +++ b/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImplTest.java @@ -164,7 +164,7 @@ void commentComparator() { .map(Comment::getMetadata) .map(MetadataOperator::getName) .collect(Collectors.joining(", ")); - assertThat(result).isEqualTo("1, 2, 3, 4, 5, 6, 9, 14, 10, 8, 7, 13, 12, 11"); + assertThat(result).isEqualTo("1, 2, 4, 3, 5, 6, 10, 14, 9, 8, 7, 11, 12, 13"); } @Test diff --git a/platform/application/build.gradle b/platform/application/build.gradle index bf775c48d2..7275d8febb 100644 --- a/platform/application/build.gradle +++ b/platform/application/build.gradle @@ -1,7 +1,7 @@ import org.springframework.boot.gradle.plugin.SpringBootPlugin plugins { - id 'org.springframework.boot' version '3.1.5' apply false + id 'org.springframework.boot' version '3.2.0-RC2' apply false id 'java-platform' id 'halo.publish' id 'signing'