Skip to content

Commit

Permalink
pref: 预览草稿时,不会增加访问量 (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajyy authored Aug 6, 2020
1 parent 782079d commit 3f2fefa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/run/halo/app/service/impl/BasePostServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,16 @@ public void increaseVisit(long visits, Integer postId) {
Assert.isTrue(visits > 0, "Visits to increase must not be less than 1");
Assert.notNull(postId, "Post id must not be null");

long affectedRows = basePostRepository.updateVisit(visits, postId);
boolean finishedIncrease;
if (basePostRepository.getByIdAndStatus(postId, PostStatus.DRAFT).isPresent())
{
finishedIncrease = true;
log.info("Post with id: [{}] is a draft and visits will not be updated", postId);
} else {
finishedIncrease = basePostRepository.updateVisit(visits, postId) == 1;
}

if (affectedRows != 1) {
if (!finishedIncrease) {
log.error("Post with id: [{}] may not be found", postId);
throw new BadRequestException("Failed to increase visits " + visits + " for post with id " + postId);
}
Expand Down

0 comments on commit 3f2fefa

Please sign in to comment.