diff --git a/api/src/main/java/run/halo/app/core/extension/content/Post.java b/api/src/main/java/run/halo/app/core/extension/content/Post.java index 430943a16a..6a616e9332 100644 --- a/api/src/main/java/run/halo/app/core/extension/content/Post.java +++ b/api/src/main/java/run/halo/app/core/extension/content/Post.java @@ -159,7 +159,7 @@ public static class PostStatus { private Instant lastModifyTime; - private long observedVersion; + private Long observedVersion; @JsonIgnore public ConditionList getConditionsOrDefault() { diff --git a/application/src/main/java/run/halo/app/infra/SchemeInitializer.java b/application/src/main/java/run/halo/app/infra/SchemeInitializer.java index 73c2d841a6..ad73b12882 100644 --- a/application/src/main/java/run/halo/app/infra/SchemeInitializer.java +++ b/application/src/main/java/run/halo/app/infra/SchemeInitializer.java @@ -153,8 +153,11 @@ public void onApplicationEvent(@NonNull ApplicationContextInitializedEvent event .setIndexFunc(simpleAttribute(Post.class, post -> { var version = post.getMetadata().getVersion(); var observedVersion = post.getStatusOrDefault().getObservedVersion(); + if (observedVersion == null || observedVersion < version) { + return BooleanUtils.TRUE; + } // do not care about the false case so return null to avoid indexing - return observedVersion >= version ? BooleanUtils.TRUE : null; + return null; }))); }); schemeManager.register(Category.class, indexSpecs -> { diff --git a/application/src/test/java/run/halo/app/content/comment/CommentServiceImplTest.java b/application/src/test/java/run/halo/app/content/comment/CommentServiceImplTest.java index c7b8e965d6..81c8a0e9c3 100644 --- a/application/src/test/java/run/halo/app/content/comment/CommentServiceImplTest.java +++ b/application/src/test/java/run/halo/app/content/comment/CommentServiceImplTest.java @@ -358,7 +358,8 @@ private String expectListResultJson() { "apiVersion": "content.halo.run/v1alpha1", "kind": "Post", "metadata": { - "name": "fake-post" + "name": "fake-post", + "version": 1 } }, "stats": { @@ -403,7 +404,8 @@ private String expectListResultJson() { "apiVersion": "content.halo.run/v1alpha1", "kind": "Post", "metadata": { - "name": "fake-post" + "name": "fake-post", + "version": 1 } }, "stats": { @@ -447,7 +449,8 @@ private String expectListResultJson() { "apiVersion": "content.halo.run/v1alpha1", "kind": "Post", "metadata": { - "name": "fake-post" + "name": "fake-post", + "version": 1 } }, "stats": {