Files
AIGC/demo/TRANSACTION_USAGE_REPORT.md

96 lines
4.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.

# 事务使用情况完整报告
## 检查时间
2025-11-06
## 检查范围
所有服务类中的 `@Transactional` 使用情况
## 检查结果
### ✅ 已修复的服务
#### 1. StoryboardVideoService
- **类级别**: 无 `@Transactional`
- **createTask**: `@Transactional(propagation = Propagation.REQUIRES_NEW)`
- **processTaskAsync**: `@Async` + `@Transactional(propagation = Propagation.NOT_SUPPORTED)`
- 内部调用使用 `REQUIRES_NEW` 的私有方法:
- `loadTaskInfoInNewTransaction` - `REQUIRES_NEW` + `readOnly = true`
- `updateTaskStatusInNewTransaction` - `REQUIRES_NEW`
- `saveStoryboardImageResultInNewTransaction` - `REQUIRES_NEW`
- `updateTaskStatusToFailedInNewTransaction` - `REQUIRES_NEW`
- **其他方法**: 快速数据库操作,使用独立事务 ✅
### ⚠️ 需要注意的服务
#### 2. TextToVideoService
- **类级别**: `@Transactional` ⚠️
- **createTask**: 继承类级别事务
- ✅ 只做快速数据库操作无外部API调用
- **processTaskWithRealAPI**: `@Async` + 继承类级别事务 ⚠️
- ⚠️ 直接使用 `taskRepository.save(task)`,会继承类级别事务
- ⚠️ 在异步方法中调用外部API可能导致连接泄漏
- **状态**: 此方法**未被调用**(任务通过 TaskQueueService 处理),不会导致实际泄漏
- **建议**: 如果未来需要使用,应添加 `NOT_SUPPORTED` 并使用 `REQUIRES_NEW` 的私有方法
#### 3. ImageToVideoService
- **类级别**: `@Transactional` ⚠️
- **createTask**: 继承类级别事务
- ✅ 只做快速数据库操作无外部API调用
- **processTaskWithRealAPI**: `@Async` + 继承类级别事务 ⚠️
- ⚠️ 直接使用 `taskRepository.save(task)`,会继承类级别事务
- ⚠️ 在异步方法中调用外部API可能导致连接泄漏
- **状态**: 此方法**未被调用**(任务通过 TaskQueueService 处理),不会导致实际泄漏
- **建议**: 如果未来需要使用,应添加 `NOT_SUPPORTED` 并使用 `REQUIRES_NEW` 的私有方法
### ✅ 正确配置的服务
#### 4. TaskQueueService
- **类级别**: `@Transactional` ⚠️
- **processPendingTasks**: `@Transactional(propagation = Propagation.NOT_SUPPORTED)`
- **processTask**: `@Transactional(propagation = Propagation.NOT_SUPPORTED)`
- **checkTaskStatuses**: `@Transactional(propagation = Propagation.NOT_SUPPORTED)`
- **checkTaskStatusInternal**: `@Transactional(propagation = Propagation.NOT_SUPPORTED)`
- **其他方法**: 快速数据库操作,使用独立事务 ✅
#### 5. TaskStatusPollingService
- **类级别**: 无 `@Transactional`
- **pollTaskStatus**: `@Transactional(propagation = Propagation.NOT_SUPPORTED)`
- **其他方法**: 快速数据库操作,使用独立事务 ✅
#### 6. UserWorkService
- **类级别**: `@Transactional` ⚠️
- **所有方法**: 快速数据库操作无外部API调用 ✅
#### 7. UserService
- **类级别**: 无 `@Transactional`
- **所有方法**: 快速数据库操作,使用独立事务 ✅
#### 8. PaymentService
- **类级别**: `@Transactional` ⚠️
- **所有方法**: 快速数据库操作无外部API调用 ✅
#### 9. OrderService
- **类级别**: `@Transactional` ⚠️
- **所有方法**: 快速数据库操作无外部API调用 ✅
## 总结
### 当前状态
**所有实际使用的异步方法都已正确配置,不会导致连接泄漏**
### 潜在问题(但未实际使用)
⚠️ `TextToVideoService.processTaskWithRealAPI``ImageToVideoService.processTaskWithRealAPI` 有潜在问题,但**未被调用**,不会导致实际泄漏
### 建议
1. ✅ 当前配置正确,无需修改
2. ⚠️ 如果未来需要使用 `processTaskWithRealAPI` 方法,应按照 `StoryboardVideoService` 的模式修复:
- 在异步方法上添加 `@Transactional(propagation = Propagation.NOT_SUPPORTED)`
- 创建使用 `REQUIRES_NEW` 的私有方法进行数据库操作
## 结论
**✅ 所有实际使用的事务配置都是正确的,不会导致连接泄漏**