diff --git a/src/main/java/run/halo/app/controller/admin/api/PostController.java b/src/main/java/run/halo/app/controller/admin/api/PostController.java index e8c05de6f..808f494ca 100644 --- a/src/main/java/run/halo/app/controller/admin/api/PostController.java +++ b/src/main/java/run/halo/app/controller/admin/api/PostController.java @@ -36,6 +36,7 @@ import run.halo.app.model.vo.PostDetailVO; import run.halo.app.service.OptionService; import run.halo.app.service.PostService; import run.halo.app.service.assembler.PostAssembler; +import run.halo.app.utils.DateUtils; import run.halo.app.utils.HaloUtils; /** @@ -164,8 +165,14 @@ public class PostController { public BasePostDetailDTO updateDraftBy( @PathVariable("postId") Integer postId, @RequestBody PostContentParam contentParam) { - Post postToUse = postService.getById(postId); + Post postToUse = postService.getWithLatestContentById(postId); String formattedContent = contentParam.decideContentBy(postToUse.getEditorType()); + // Update the editTime when the content of the posts changes + if (!postToUse.getContent().getOriginalContent() + .equals(contentParam.getOriginalContent())) { + postToUse.setEditTime(DateUtils.now()); + postService.update(postToUse); + } // Update draft content Post post = postService.updateDraftContent(formattedContent, contentParam.getOriginalContent(), postId); diff --git a/src/main/java/run/halo/app/model/params/BasePostParam.java b/src/main/java/run/halo/app/model/params/BasePostParam.java index eab89e6a4..527d00e79 100644 --- a/src/main/java/run/halo/app/model/params/BasePostParam.java +++ b/src/main/java/run/halo/app/model/params/BasePostParam.java @@ -10,7 +10,7 @@ import run.halo.app.model.entity.BasePost; import run.halo.app.model.entity.Content; import run.halo.app.model.enums.PostEditorType; import run.halo.app.model.enums.PostStatus; -import run.halo.app.service.impl.BasePostServiceImpl; +import run.halo.app.utils.DateUtils; import run.halo.app.utils.MarkdownUtils; /** @@ -73,6 +73,13 @@ public abstract class BasePostParam { } else { postContent.setContent(content); } + + // update the editTime only when changing the post title or post content + if (!Objects.equals(title, post.getTitle()) + || !Objects.equals(originalContent, post.getContent().getOriginalContent())) { + post.setEditTime(DateUtils.now()); + } + post.setContent(Content.PatchedContent.of(postContent)); } } diff --git a/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java b/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java index 5e148a2c0..40dadbe69 100644 --- a/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java @@ -314,8 +314,6 @@ public abstract class BasePostServiceImpl postContent.getContent(), postContent.getOriginalContent()); } else { // The sheet will be updated - // Set edit time - post.setEditTime(DateUtils.now()); contentService.createOrUpdateDraftBy(post.getId(), postContent.getContent(), postContent.getOriginalContent()); // Update it diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index 4ba2a96c9..220255f24 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -194,8 +194,6 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe @Transactional(rollbackFor = Exception.class) public PostDetailVO updateBy(Post postToUpdate, Set tagIds, Set categoryIds, Set metas, boolean autoSave) { - // Set edit time - postToUpdate.setEditTime(DateUtils.now()); PostDetailVO updatedPost = createOrUpdate(postToUpdate, tagIds, categoryIds, metas); if (!autoSave) { // Log the creation