mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-07 18:47:44 +08:00
fix: 处理首屏返回空的问题
This commit is contained in:
@@ -203,8 +203,8 @@ public class PostController {
|
|||||||
// userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return postService.listPostsByLatestReply(ids, tids, page, pageSize)
|
List<Post> posts = postService.listPostsByLatestReply(ids, tids, page, pageSize);
|
||||||
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
return posts.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/featured")
|
@GetMapping("/featured")
|
||||||
|
|||||||
@@ -96,8 +96,6 @@ public class PostMapper {
|
|||||||
l.setPointCost(lp.getPointCost());
|
l.setPointCost(lp.getPointCost());
|
||||||
l.setStartTime(lp.getStartTime());
|
l.setStartTime(lp.getStartTime());
|
||||||
l.setEndTime(lp.getEndTime());
|
l.setEndTime(lp.getEndTime());
|
||||||
l.setParticipants(lp.getParticipants().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
|
||||||
l.setWinners(lp.getWinners().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
|
||||||
dto.setLottery(l);
|
dto.setLottery(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +104,6 @@ public class PostMapper {
|
|||||||
p.setOptions(pp.getOptions());
|
p.setOptions(pp.getOptions());
|
||||||
p.setVotes(pp.getVotes());
|
p.setVotes(pp.getVotes());
|
||||||
p.setEndTime(pp.getEndTime());
|
p.setEndTime(pp.getEndTime());
|
||||||
p.setParticipants(pp.getParticipants().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
|
||||||
Map<Integer, List<AuthorDto>> optionParticipants = pollVoteRepository.findByPostId(pp.getId()).stream()
|
Map<Integer, List<AuthorDto>> optionParticipants = pollVoteRepository.findByPostId(pp.getId()).stream()
|
||||||
.collect(Collectors.groupingBy(PollVote::getOptionIndex,
|
.collect(Collectors.groupingBy(PollVote::getOptionIndex,
|
||||||
Collectors.mapping(v -> userMapper.toAuthorDto(v.getUser()), Collectors.toList())));
|
Collectors.mapping(v -> userMapper.toAuthorDto(v.getUser()), Collectors.toList())));
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ public class UserVisitScheduler {
|
|||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final UserVisitRepository userVisitRepository;
|
private final UserVisitRepository userVisitRepository;
|
||||||
|
|
||||||
@Scheduled(cron = "0 5 0 * * ?")// 每天 00:05 执行
|
@Scheduled(cron = "0 5 0 * * ?") // 每天 00:05 执行
|
||||||
public void persistDailyVisits(){
|
public void persistDailyVisits(){
|
||||||
LocalDate yesterday = LocalDate.now().minusDays(1);
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
||||||
String key = CachingConfig.VISIT_CACHE_NAME+":"+ yesterday;
|
String key = CachingConfig.VISIT_CACHE_NAME + ":" + yesterday;
|
||||||
Set<String> usernames = redisTemplate.opsForSet().members(key);
|
Set<String> usernames = redisTemplate.opsForSet().members(key);
|
||||||
if(!CollectionUtils.isEmpty(usernames)){
|
if (!CollectionUtils.isEmpty(usernames)) {
|
||||||
for(String username: usernames){
|
for(String username: usernames){
|
||||||
User user = userRepository.findByUsername(username).orElse(null);
|
User user = userRepository.findByUsername(username).orElse(null);
|
||||||
if(user != null){
|
if(user != null){
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ public class UserVisitService {
|
|||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
|
|
||||||
// 如果缓存存在就返回
|
// 如果缓存存在就返回
|
||||||
String key1 = CachingConfig.VISIT_CACHE_NAME + ":"+LocalDate.now()+":count:"+username;
|
String key1 = CachingConfig.VISIT_CACHE_NAME + ":" +LocalDate.now() + ":count:" + username;
|
||||||
Integer cached = (Integer) redisTemplate.opsForValue().get(key1);
|
Integer cached = (Integer) redisTemplate.opsForValue().get(key1);
|
||||||
if(cached != null){
|
if (cached != null){
|
||||||
return cached.longValue();
|
return cached.longValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user