mirror of https://github.com/halo-dev/halo
fix:repeated updates of visits and private article visits abnorm… (#463)
parent
6c7968cc2b
commit
0ce380072e
|
@ -35,6 +35,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
*
|
||||
* @author ryanwang
|
||||
* @author guqing
|
||||
* @author evanwang
|
||||
* @date 2019-03-17
|
||||
*/
|
||||
@Slf4j
|
||||
|
@ -135,7 +136,7 @@ public class ContentArchiveController {
|
|||
}
|
||||
post.setFormatContent(MarkdownUtils.renderHtml(post.getOriginalContent()));
|
||||
}
|
||||
|
||||
postService.publishVisitEvent(post.getId());
|
||||
postService.getNextPost(post.getCreateTime()).ifPresent(nextPost -> model.addAttribute("nextPost", nextPost));
|
||||
postService.getPrePost(post.getCreateTime()).ifPresent(prePost -> model.addAttribute("prePost", prePost));
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
* Content sheet controller.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @author evanwang
|
||||
* @date 2019-03-21
|
||||
*/
|
||||
@Controller
|
||||
|
@ -119,6 +120,7 @@ public class ContentSheetController {
|
|||
throw new ForbiddenException("您没有该页面的访问权限");
|
||||
}
|
||||
}
|
||||
sheetService.publishVisitEvent(sheet.getId());
|
||||
|
||||
SheetDetailVO sheetDetailVO = sheetService.convertToDetailVo(sheet);
|
||||
|
||||
|
|
|
@ -182,4 +182,11 @@ public interface PostService extends BasePostService<Post> {
|
|||
* @return a page of post detail vo
|
||||
*/
|
||||
Page<PostDetailVO> convertToDetailVo(@NonNull Page<Post> postPage);
|
||||
|
||||
/**
|
||||
* Publish a post visit event.
|
||||
*
|
||||
* @param postId postId must not be null
|
||||
*/
|
||||
void publishVisitEvent(@NonNull Integer postId);
|
||||
}
|
||||
|
|
|
@ -124,4 +124,11 @@ public interface SheetService extends BasePostService<Sheet> {
|
|||
*/
|
||||
@NonNull
|
||||
SheetDetailVO convertToDetailVo(@NonNull Sheet sheet);
|
||||
|
||||
/**
|
||||
* Publish a sheet visit event.
|
||||
*
|
||||
* @param sheetId sheetId must not be null
|
||||
*/
|
||||
void publishVisitEvent(@NonNull Integer sheetId);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @author guqing
|
||||
* @author evanwang
|
||||
* @date 2019-03-14
|
||||
*/
|
||||
@Slf4j
|
||||
|
@ -159,8 +160,6 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
public Post getBy(PostStatus status, String url) {
|
||||
Post post = super.getBy(status, url);
|
||||
|
||||
fireVisitEvent(post.getId());
|
||||
|
||||
return post;
|
||||
}
|
||||
|
||||
|
@ -176,8 +175,6 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
public Post getByUrl(String url) {
|
||||
Post post = super.getByUrl(url);
|
||||
|
||||
fireVisitEvent(post.getId());
|
||||
|
||||
return post;
|
||||
}
|
||||
|
||||
|
@ -630,7 +627,8 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
return convertTo(post, tags, categories, postMetaList);
|
||||
}
|
||||
|
||||
private void fireVisitEvent(@NonNull Integer postId) {
|
||||
@Override
|
||||
public void publishVisitEvent(Integer postId) {
|
||||
eventPublisher.publishEvent(new PostVisitEvent(this, postId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.*;
|
|||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @author evanwang
|
||||
* @date 2019-04-24
|
||||
*/
|
||||
@Slf4j
|
||||
|
@ -130,8 +131,6 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
|
||||
Sheet sheet = sheetRepository.getByUrl(url).orElseThrow(() -> new NotFoundException("查询不到该页面的信息").setErrorData(url));
|
||||
|
||||
fireVisitEvent(sheet.getId());
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
|
@ -144,8 +143,6 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
|
||||
Sheet sheet = postOptional.orElseThrow(() -> new NotFoundException("查询不到该页面的信息").setErrorData(url));
|
||||
|
||||
fireVisitEvent(sheet.getId());
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
|
@ -261,7 +258,8 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
});
|
||||
}
|
||||
|
||||
private void fireVisitEvent(@NonNull Integer sheetId) {
|
||||
@Override
|
||||
public void publishVisitEvent(Integer sheetId) {
|
||||
eventPublisher.publishEvent(new SheetVisitEvent(this, sheetId));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue