From e208e158b09b289cc454e4885f2eb1c13ab25e24 Mon Sep 17 00:00:00 2001 From: guqing Date: Thu, 25 Jan 2024 16:16:36 +0800 Subject: [PATCH] refactor: change data type for observedVersion --- .../java/run/halo/app/core/extension/content/Post.java | 2 +- .../main/java/run/halo/app/infra/SchemeInitializer.java | 3 ++- .../halo/app/content/comment/CommentServiceImplTest.java | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) 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 430943a16a1..6a616e9332c 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 73c2d841a6f..245adcdf77b 100644 --- a/application/src/main/java/run/halo/app/infra/SchemeInitializer.java +++ b/application/src/main/java/run/halo/app/infra/SchemeInitializer.java @@ -154,7 +154,8 @@ public void onApplicationEvent(@NonNull ApplicationContextInitializedEvent event var version = post.getMetadata().getVersion(); var observedVersion = post.getStatusOrDefault().getObservedVersion(); // do not care about the false case so return null to avoid indexing - return observedVersion >= version ? BooleanUtils.TRUE : null; + return (observedVersion != null && observedVersion >= version) + ? BooleanUtils.TRUE : 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 c7b8e965d61..81c8a0e9c32 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": {