fix: 修复回忆列表并发死锁并收敛多表查询
This commit is contained in:
@@ -6,8 +6,12 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ReviewRecallMapper extends BaseMapper<ReviewRecallEntity> {
|
||||
// 命中已有行时必须走「独占锁」而不是 INSERT IGNORE 的共享锁:否则本事务随后的 SELECT ... FOR UPDATE
|
||||
// 要做 S→X 升级,两个并发请求各持共享锁互等,InnoDB 直接判定死锁并回滚其一(前端表现为 500)。
|
||||
@com.baomidou.mybatisplus.annotation.InterceptorIgnore(tenantLine = "true")
|
||||
@org.apache.ibatis.annotations.Insert("INSERT IGNORE INTO review_recall_owner_locks (owner_id) VALUES (#{userId})")
|
||||
@org.apache.ibatis.annotations.Insert(
|
||||
"INSERT INTO review_recall_owner_locks (owner_id) VALUES (#{userId})"
|
||||
+ " ON DUPLICATE KEY UPDATE owner_id = owner_id")
|
||||
int ensureOwnerLock(@org.apache.ibatis.annotations.Param("userId") String userId);
|
||||
|
||||
// Dedicated lock row, not a login/session mutation. Explicit owner id prevents cross-user locking.
|
||||
@@ -16,14 +20,18 @@ public interface ReviewRecallMapper extends BaseMapper<ReviewRecallEntity> {
|
||||
"SELECT owner_id FROM review_recall_owner_locks WHERE owner_id = #{userId} FOR UPDATE")
|
||||
String lockUser(@org.apache.ibatis.annotations.Param("userId") String userId);
|
||||
|
||||
@org.apache.ibatis.annotations.Select(
|
||||
"SELECT task_num, SUM(active_duration_ms) AS active_duration_ms FROM review_recalls WHERE deleted = 0 AND"
|
||||
+ " scope_type = 'TASK' GROUP BY task_num")
|
||||
@org.apache.ibatis.annotations.Select("<script>"
|
||||
+ "SELECT task_num, SUM(active_duration_ms) AS active_duration_ms FROM review_recalls WHERE deleted = 0 AND"
|
||||
+ " scope_type = 'TASK'"
|
||||
+ " <if test='taskNums != null and taskNums.size() > 0'>AND task_num IN"
|
||||
+ " <foreach item='num' collection='taskNums' open='(' separator=',' close=')'>#{num}</foreach></if>"
|
||||
+ " GROUP BY task_num</script>")
|
||||
@org.apache.ibatis.annotations.Results(
|
||||
id = "taskRecallDuration",
|
||||
value = {
|
||||
@org.apache.ibatis.annotations.Result(column = "task_num", property = "taskNum"),
|
||||
@org.apache.ibatis.annotations.Result(column = "active_duration_ms", property = "activeDurationMs")
|
||||
})
|
||||
java.util.List<com.guo.learningprogresstracker.dto.recall.TaskRecallDuration> sumTaskDuration();
|
||||
java.util.List<com.guo.learningprogresstracker.dto.recall.TaskRecallDuration> sumTaskDuration(
|
||||
@org.apache.ibatis.annotations.Param("taskNums") java.util.Collection<String> taskNums);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user