pref: 预览草稿时,不会增加访问量 (#834)

pull/1025/head
Junyi Ao 2020-08-06 22:35:30 +08:00 committed by GitHub
parent 782079dc9f
commit 3f2fefaf22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -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);
}