SIGN IN SIGN UP

利用AI大模型,一键生成高清短视频 Generate short videos with one click using AI LLM.

0 0 14 Python

refactor: optimize codebase for better performance and reliability

## Key Optimizations:

### 1. video.py (app/services/video.py)
- Remove unused variable calculation (req_dur)
- Fix resource access after close by saving clip.duration before closing
- Improve error handling in delete_files() with proper logging
- Better code clarity and maintainability

### 2. material.py (app/services/material.py)
- Fix thread-safety issue: replace global counter with thread-safe implementation using threading.Lock
- Fix resource leak: ensure VideoFileClip is properly closed using try-finally block
- Improve exception handling and resource cleanup
- Prevents potential race conditions in concurrent scenarios

### 3. video.py controller (app/controllers/v1/video.py)
- Fix critical bug: use correct variable 'file' instead of 'v' in file_to_uri()
- Prevents NameError and ensures proper URI generation for task files

### 4. utils.py (app/utils/utils.py)
- Improve error logging in to_json() with proper error messages
- Add exc_info=True to background thread error logging for better debugging
- Make background threads non-daemon for more predictable behavior

## Impact:
- Better thread-safety for concurrent video generation tasks
- Reduced resource leaks and memory issues
- Improved error visibility and debugging capability
- More robust error handling throughout the codebase
- Fixed potential runtime errors in URI generation

## Testing:
- All changes are backward compatible
- No breaking changes to public APIs
- Improved reliability for production use
C
Claude committed
44096d608651e66063d3abd75063626fc6f8844a
Parent: 6cb5f23