main
forely 4 weeks ago
parent a467856a7c
commit cb5b133cc6

@ -35,7 +35,8 @@ public class PostSelector {
double newScore = (1 + likes + comments*0.7 + favorites*0.5) double newScore = (1 + likes + comments*0.7 + favorites*0.5)
/ Math.pow(1 + hours/24.0, 1.8); / Math.pow(1 + hours/24.0, 1.8);
redisUtil.zAdd("post:hot:", post.getId(), newScore); redisUtil.zAdd("post:hot:"+post.getCategoryId(), post.getId(), newScore);
redisUtil.zAdd("post:hot:all", post.getId(), newScore);
} }
public void calculateCommentScore(Comment comment){ public void calculateCommentScore(Comment comment){

@ -14,4 +14,6 @@ public class PostPageQueryDTO extends ScrollPageRequest {
@Schema(title = "排序类型0表示按时间1表示按热度2表示自定义的推荐算法(暂未实现)") @Schema(title = "排序类型0表示按时间1表示按热度2表示自定义的推荐算法(暂未实现)")
private Integer type = 0; private Integer type = 0;
private Long categoryId;
} }

@ -77,5 +77,8 @@ public class PostBasicInfoDTO {
@Schema( @Schema(
description = "帖子创建时间" description = "帖子创建时间"
) )
private Long categoryId;
private LocalDateTime createTime; private LocalDateTime createTime;
} }

@ -82,5 +82,8 @@ public class PostInfoDTO {
@Schema( @Schema(
description = "帖子创建时间" description = "帖子创建时间"
) )
private Long categoryId;
private LocalDateTime createTime; private LocalDateTime createTime;
} }

@ -91,7 +91,8 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
// TODO 消息通知? // TODO 消息通知?
} }
postSelector.calculatePostScore(post); postSelector.calculatePostScore(post);
redisUtil.zAdd("post:time:", post.getId(), System.currentTimeMillis()); redisUtil.zAdd("post:time:"+post.getCategoryId(), post.getId(), System.currentTimeMillis());
redisUtil.zAdd("post:time:"+"all", post.getId(), System.currentTimeMillis());
redisUtil.zAdd("post:user:" + userId, post.getId(), System.currentTimeMillis()); redisUtil.zAdd("post:user:" + userId, post.getId(), System.currentTimeMillis());
return post.getId(); return post.getId();
} }
@ -119,6 +120,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
public void deletePost(Long id) { public void deletePost(Long id) {
validatePostUtil.validatePostOwnership(id); validatePostUtil.validatePostOwnership(id);
Long userId = UserContext.getUserId(); Long userId = UserContext.getUserId();
Post post = postMapper.selectById(id);
int delete = postMapper.deleteById(id); int delete = postMapper.deleteById(id);
if(delete <= 0){ if(delete <= 0){
throw new PostException("删除帖子失败"); throw new PostException("删除帖子失败");
@ -126,8 +128,10 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
// redisUtil.delete("post:detail:" + id.toString()); // redisUtil.delete("post:detail:" + id.toString());
// redisUtil.delete("post:of:user:" + UserContext.getUserId()); // redisUtil.delete("post:of:user:" + UserContext.getUserId());
redisUtil.delete("post:detail:" + id); redisUtil.delete("post:detail:" + id);
redisUtil.zRemove("post:time:", id); redisUtil.zRemove("post:time:"+post.getCategoryId(), id);
redisUtil.zRemove("post:hot:", id); redisUtil.zRemove("post:hot:"+post.getCategoryId(), id);
redisUtil.zRemove("post:time:"+"all", id);
redisUtil.zRemove("post:hot:"+"all", id);
redisUtil.zRemove("post:user:" + userId, id); redisUtil.zRemove("post:user:" + userId, id);
} }
@ -184,7 +188,12 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
return postBasicInfoDTO; return postBasicInfoDTO;
}); });
*/ */
String key = postPageQueryDTO.getType().equals(0) ? "post:time:" : "post:hot:"; String key;
if(postPageQueryDTO.getCategoryId() == null || postPageQueryDTO.getCategoryId().equals(0L)){
key = (postPageQueryDTO.getType().equals(0) ? "post:time:" : "post:hot:") + "all";
}else {
key = (postPageQueryDTO.getType().equals(0) ? "post:time:" : "post:hot:") + postPageQueryDTO.getCategoryId();
}
return redisUtil.scrollPageQuery(key, PostBasicInfoDTO.class, postPageQueryDTO, return redisUtil.scrollPageQuery(key, PostBasicInfoDTO.class, postPageQueryDTO,
(postIds) -> { (postIds) -> {
List<Long> userIds = new ArrayList<>(); List<Long> userIds = new ArrayList<>();

@ -1,21 +1,20 @@
##本地开发环境 lj:
#lj: db:
# db: host: 192.168.59.129
# host: 192.168.59.129 password: Forely123!
# password: Forely123! redis:
# redis: host: 192.168.59.129
# host: 192.168.59.129 port: 6379
# port: 6379 password: Forely123!
# password: Forely123! rabbitmq:
# rabbitmq: host: 192.168.59.129
# host: 192.168.59.129 port: 5672
# port: 5672 username: admin
# username: admin password: Forely123!
# password: Forely123! minio:
# minio: endpoint: http://192.168.59.129:9000
# endpoint: http://192.168.59.129:9000 accessKey: forely
# accessKey: forely secretKey: Forely123!
# secretKey: Forely123!
#lj: #lj:
# db: # db:
@ -35,20 +34,20 @@
# accessKey: minio_admin # accessKey: minio_admin
# secretKey: Minio@1234 # secretKey: Minio@1234
lj: #lj:
db: # db:
host: localhost # host: localhost
password: 123456 # password: 123456
redis: # redis:
host: localhost # host: localhost
port: 6379 # port: 6379
password: 123456 # password: 123456
rabbitmq: # rabbitmq:
host: localhost # host: localhost
port: 5672 # port: 5672
username: guest # username: guest
password: guest # password: guest
minio: # minio:
endpoint: http://localhost:9005 # endpoint: http://localhost:9005
accessKey: leezt # accessKey: leezt
secretKey: lzt264610 # secretKey: lzt264610

@ -49,6 +49,10 @@ spring:
concurrency: 5 concurrency: 5
max-concurrency: 10 max-concurrency: 10
prefetch: 1 prefetch: 1
servlet:
multipart:
max-file-size: 10MB
max-request-size: 10MB
# minio配置 # minio配置
minio: minio:
endpoint: ${lj.minio.endpoint} endpoint: ${lj.minio.endpoint}

Loading…
Cancel
Save