mirror of https://github.com/halo-dev/halo
pref: 预览草稿时,不会增加访问量 (#834)
parent
782079dc9f
commit
3f2fefaf22
|
@ -215,9 +215,16 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue