Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/post-index
Browse files Browse the repository at this point in the history
  • Loading branch information
guqing committed Jan 23, 2024
2 parents 5faccd9 + 8523a67 commit 66eb97f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 26 deletions.
3 changes: 3 additions & 0 deletions api/src/main/java/run/halo/app/extension/ListResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public static <T> ListResult<T> emptyResult() {
*/
public static <T> List<T> subList(List<T> list, int page, int size) {
if (page < 1) {
page = 1;
}
if (size < 1) {
return list;
}
List<T> listSort = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import de.undercouch.gradle.tasks.download.Download
import org.gradle.crypto.checksum.Checksum

plugins {
id 'org.springframework.boot' version '3.2.0'
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.0'
id "com.gorylenko.gradle-git-properties" version "2.3.2"
id "checkstyle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static Comparator<Reply> creationTimeAscComparator() {
reply -> reply.getMetadata().getCreationTimestamp();
// ascending order by creation time
// asc nulls high will be placed at the end
return Comparator.comparing(creationTime, Comparators.nullsLow())
return Comparator.comparing(creationTime, Comparators.nullsHigh())
.thenComparing(metadataCreationTime)
.thenComparing(reply -> reply.getMetadata().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,12 @@ static IndexEntry getIndexEntry(String fieldPath, Map<String, IndexEntry> fieldP
return fieldPathEntryMap.get(fieldPath);
}

static <T> List<T> paginate(List<T> list, int page, int size) {
if (list == null) {
return new ArrayList<>();
}

if (size == 0) {
return new ArrayList<>(list);
}

int fromIndex = (page - 1) * size;
if (fromIndex >= list.size() || fromIndex < 0) {
return new ArrayList<>();
}

int toIndex = Math.min(fromIndex + size, list.size());
return new ArrayList<>(list.subList(fromIndex, toIndex));
}

@Override
public ListResult<String> retrieve(GroupVersionKind type, ListOptions options,
PageRequest page) {
var indexer = indexerFactory.getIndexer(type);
var allMatchedResult = doRetrieve(indexer, options, page.getSort());
var list = paginate(allMatchedResult, page.getPageNumber(), page.getPageSize());
var list = ListResult.subList(allMatchedResult, page.getPageNumber(), page.getPageSize());
return new ListResult<>(page.getPageNumber(), page.getPageSize(),
allMatchedResult.size(), list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public Map<String, Object> getErrorAttributes(ServerRequest request,
@Override
public Throwable getError(ServerRequest request) {
return (Throwable) request.attribute(ERROR_INTERNAL_ATTRIBUTE).stream()
.peek(error -> request.attributes().putIfAbsent(ERROR_ATTRIBUTE, error))
.findFirst()
.orElseThrow(() -> new IllegalStateException(
"Missing exception attribute in ServerWebExchange"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public int compare(Comment c1, Comment c2) {

var creationTimeComparator = Comparator.<Comment, Instant>comparing(
comment -> comment.getSpec().getCreationTime(),
Comparators.nullsLow(Comparator.<Instant>reverseOrder()));
Comparators.nullsHigh(Comparator.<Instant>reverseOrder()));

var nameComparator = Comparator.<Comment, String>comparing(
comment -> comment.getMetadata().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
rbac.authorization.halo.run/system-reserved: "true"
annotations:
# Currently, yaml definition does not support i18n, please see https://github.com/halo-dev/halo/issues/3573
rbac.authorization.halo.run/display-name: "编辑者"
rbac.authorization.halo.run/display-name: "文章管理员"
rbac.authorization.halo.run/dependencies: |
["role-template-post-editor"]
rules: [ ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,26 @@ void totalPages() {
listResult = new ListResult<>(1, 0, 100, List.of());
assertEquals(1, listResult.getTotalPages());
}

@Test
void subListWhenSizeIsZero() {
var list = List.of(1, 2, 3, 4, 5);
assertSubList(list);

list = List.of(1);
assertSubList(list);
}

private void assertSubList(List<Integer> list) {
var result = ListResult.subList(list, 0, 0);
assertEquals(list, result);

result = ListResult.subList(list, 0, 1);
assertEquals(list.subList(0, 1), result);

result = ListResult.subList(list, 1, 0);
assertEquals(list, result);

assertEquals(list.subList(0, 1), ListResult.subList(list, -1, 1));
}
}
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
version=2.12.0-SNAPSHOT
snakeyaml.version=2.2
2 changes: 1 addition & 1 deletion platform/application/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.springframework.boot.gradle.plugin.SpringBootPlugin

plugins {
id 'org.springframework.boot' version '3.2.0' apply false
id 'org.springframework.boot' version '3.2.2' apply false
id 'java-platform'
id 'halo.publish'
id 'signing'
Expand Down

0 comments on commit 66eb97f

Please sign in to comment.