Compare commits

..
3 Commits
Author SHA1 Message Date
wonder 9c54288835 🔧Chore: 初始化 Maven 项目 2025-10-17 23:01:56 +08:00
wonder 98785fc421 📝Docs: 编写数据库初始化脚本 2025-10-17 22:59:29 +08:00
wonder c395909d43 📝Docs: 增加模块规划 2025-10-17 22:34:47 +08:00
4 changed files with 93 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
.idea/
+35 -1
View File
@@ -1,3 +1,37 @@
# thumb-up # thumb-up
🧐 高并发点赞系统 🧐 高并发点赞系统
## 模块
### 用户模块
1. 登录
- 使用 Session 简单登录
2. 用户信息
- 不是本项目讨论的重点,不提供修改
### 点赞模块
1. 校验
- 参数合法性
- 登录态
- 是否已点赞
2. 锁
- 多次点赞统一博客场景
3. 事务
- 修改两张表,需要保证数据一致性
### 博客模块
1. 获取博客
2. 获取博客列表
## QA
1. 如何从数据库层面杜绝重复数据出现?
答:对于 `thumb` 表,使用联合唯一索引
```mysql
CREATE UNIQUE INDEX idx_userId_blogId ON thumb (userId, blogId);
```
+36
View File
@@ -0,0 +1,36 @@
# 创建数据库
CREATE DATABASE IF NOT EXISTS thumb_up;
# 切换数据库
USE thumb_up;
# 用户表
CREATE TABLE IF NOT EXISTS user
(
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT 'id',
username VARCHAR(128) NOT NULL COMMENT '用户名'
);
# 博客表
CREATE TABLE IF NOT EXISTS blog
(
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT 'id',
userId BIGINT NOT NULL COMMENT '用户 id',
title VARCHAR(512) NULL COMMENT '标题',
coverImg VARCHAR(1024) NULL COMMENT '封面',
content TEXT NOT NULL COMMENT '内容',
thumbCount INT DEFAULT 0 NOT NULL COMMENT '点赞数',
createTime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间',
updateTime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
);
CREATE INDEX idx_userId ON blog(userId);
# 点赞记录表
CREATE TABLE IF NOT EXISTS thumb
(
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT 'id',
userId BIGINT NOT NULL COMMENT '用户 id',
blogId BIGINT NOT NULL COMMENT '博客 id',
createTime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间'
);
CREATE UNIQUE INDEX idx_userId_blogId ON thumb (userId, blogId) ;
+21
View File
@@ -0,0 +1,21 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.hezhaohui</groupId>
<artifactId>thumb</artifactId>
<version>1.0-SNAPSHOT</version>
<name>thumb-up</name>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
</dependencies>
</project>