Files
thumb-up/README.md
T
2025-10-18 23:02:08 +08:00

44 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# thumb-up
🧐 高并发点赞系统
## 模块
### 用户模块
1. 登录
- 使用 Session 简单登录
2. 用户信息
- 不是本项目讨论的重点,不提供修改
### 点赞模块
1. 校验
- 参数合法性
- 登录态
- 是否已点赞
2. 锁
- 多次点赞统一博客场景
3. 事务
- 修改两张表,需要保证数据一致性
### 博客模块
1. 获取博客
2. 获取博客列表
## QA
1. 如何从数据库层面杜绝重复数据出现?
答:对于 `thumb` 表,使用联合唯一索引
```mysql
CREATE UNIQUE INDEX idx_userId_blogId ON thumb (userId, blogId);
```
2. 为什么要在 `BlogServiceImpl` 导入 `ThumbService` 上加 `@Lazy`
答:
- 博客服务中需要使用点赞服务查询博客对应的点赞情况列表以返回对应视图。
- 点赞服务中需要使用博客服务更新单条博客的点赞计数器。
- 两个服务之间产生了**循环依赖**,Spring Boot 2.6 以后的版本默认不允许循环依赖,这里可以使用懒加载的方式避免这一问题。