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)
/ 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){

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

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

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

@ -91,7 +91,8 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
// TODO 消息通知?
}
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());
return post.getId();
}
@ -119,6 +120,7 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
public void deletePost(Long id) {
validatePostUtil.validatePostOwnership(id);
Long userId = UserContext.getUserId();
Post post = postMapper.selectById(id);
int delete = postMapper.deleteById(id);
if(delete <= 0){
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:of:user:" + UserContext.getUserId());
redisUtil.delete("post:detail:" + id);
redisUtil.zRemove("post:time:", id);
redisUtil.zRemove("post:hot:", id);
redisUtil.zRemove("post:time:"+post.getCategoryId(), 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);
}
@ -184,7 +188,12 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
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,
(postIds) -> {
List<Long> userIds = new ArrayList<>();

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

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

Loading…
Cancel
Save