bugFix: (note)
- Bloom 布隆过滤器不存在时,未校验是否点赞其他笔记
This commit is contained in:
@@ -598,10 +598,13 @@ public class NoteServiceImpl extends ServiceImpl<NoteDOMapper, NoteDO> implement
|
|||||||
// 目标笔记已经被点赞
|
// 目标笔记已经被点赞
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
// 异步初始化布隆过滤器
|
// 异步初始化布隆过滤器
|
||||||
asynBatchAddNoteLike2BloomAndExpire(userId, expireSeconds, bloomUserNoteLikeListKey);
|
threadPoolTaskExecutor.submit(() -> batchAddNoteLike2BloomAndExpire(userId, expireSeconds, bloomUserNoteLikeListKey));
|
||||||
throw new ApiException(ResponseCodeEnum.NOTE_ALREADY_LIKED);
|
throw new ApiException(ResponseCodeEnum.NOTE_ALREADY_LIKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 若笔记未被点赞,查询当前用户是否点赞其他用户,有则同步初始化布隆过滤器
|
||||||
|
batchAddNoteLike2BloomAndExpire(userId, expireSeconds, bloomUserNoteLikeListKey);
|
||||||
|
|
||||||
// 若数据库中也没有点赞记录,说明该用户还未点赞过任何笔记
|
// 若数据库中也没有点赞记录,说明该用户还未点赞过任何笔记
|
||||||
// Lua 脚本路径
|
// Lua 脚本路径
|
||||||
script.setScriptSource(new ResourceScriptSource(new ClassPathResource("/lua/bloom_add_note_like_and_expire.lua")));
|
script.setScriptSource(new ResourceScriptSource(new ClassPathResource("/lua/bloom_add_note_like_and_expire.lua")));
|
||||||
@@ -764,17 +767,19 @@ public class NoteServiceImpl extends ServiceImpl<NoteDOMapper, NoteDO> implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步批量添加笔记点赞记录到布隆过滤器中,并设置过期时间
|
* 异步初始化布隆过滤器
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param expireSeconds 过期时间(秒)
|
* @param expireSeconds 过期时间(秒)
|
||||||
* @param bloomUserNoteLikeListKey 布隆过滤器 Key
|
* @param bloomUserNoteLikeListKey 布隆过滤器 KEY
|
||||||
*/
|
*/
|
||||||
private void asynBatchAddNoteLike2BloomAndExpire(Long userId, long expireSeconds, String bloomUserNoteLikeListKey) {
|
private void batchAddNoteLike2BloomAndExpire(Long userId, long expireSeconds, String bloomUserNoteLikeListKey) {
|
||||||
threadPoolTaskExecutor.submit(() -> {
|
|
||||||
try {
|
try {
|
||||||
|
// 异步全量同步一下,并设置过期时间
|
||||||
List<NoteLikeDO> noteLikeDOS = noteLikeDOService.list(new LambdaQueryWrapper<>(NoteLikeDO.class)
|
List<NoteLikeDO> noteLikeDOS = noteLikeDOService.list(new LambdaQueryWrapper<>(NoteLikeDO.class)
|
||||||
.eq(NoteLikeDO::getUserId, userId));
|
.select(NoteLikeDO::getNoteId)
|
||||||
|
.eq(NoteLikeDO::getUserId, userId)
|
||||||
|
.eq(NoteLikeDO::getStatus, LikeStatusEnum.LIKE.getCode()));
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(noteLikeDOS)) {
|
if (CollUtil.isNotEmpty(noteLikeDOS)) {
|
||||||
DefaultRedisScript<Long> script = new DefaultRedisScript<>();
|
DefaultRedisScript<Long> script = new DefaultRedisScript<>();
|
||||||
// Lua 脚本路径
|
// Lua 脚本路径
|
||||||
@@ -789,9 +794,8 @@ public class NoteServiceImpl extends ServiceImpl<NoteDOMapper, NoteDO> implement
|
|||||||
redisTemplate.execute(script, Collections.singletonList(bloomUserNoteLikeListKey), luaArgs.toArray());
|
redisTemplate.execute(script, Collections.singletonList(bloomUserNoteLikeListKey), luaArgs.toArray());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("异步批量添加笔记点赞记录到布隆过滤器中,并设置过期时间失败...", e);
|
log.error("## 异步初始化布隆过滤器异常: ", e);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user