Feature: POST-based diagram generation with local caching #2
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/diagram-post-caching"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Overview
This PR implements POST-based diagram generation with local filesystem caching to replace the current URL-encoded GET approach.
Changes
New Features
Files Added
diagramm_proxy/__init__.py- Module initializationdiagramm_proxy/diagram_cache.py- Core caching logic with POST request handlingabschnitte/management/commands/clear_diagram_cache.py- Management command for cache clearingDocumentation/DIAGRAM_CACHING.md- Complete feature documentationFiles Modified
abschnitte/utils.py- Updated diagram rendering to use POST with caching.gitignore- Added diagram cache directory exclusionBenefits
Configuration Required
Add to Django settings:
Ensure media files are served (see Documentation/DIAGRAM_CACHING.md for details).
Testing
Migration Notes
requestslibrary already in requirements.txtSee
Documentation/DIAGRAM_CACHING.mdfor complete setup and usage instructions.Additional Configuration Added
I've added the necessary Django configuration to serve media files (including cached diagrams):
Files Updated:
VorgabenUI/settings.py- Added:MEDIA_URL = '/media/'MEDIA_ROOT = os.path.join(BASE_DIR, 'media')DIAGRAM_CACHE_DIR = 'diagram_cache'VorgabenUI/settings-docker.py- Added the same media configuration for Docker deploymentVorgabenUI/urls.py- Added:What This Fixes:
Django couldn't find the cached diagrams because there was no URL mapping for the
/media/path. Now:media/diagram_cache/{type}/{hash}.svg/media/diagram_cache/{type}/{hash}.svgTesting:
After merging, diagrams should now:
No additional configuration needed - it's all included in the PR!
✅ Comprehensive Test Suite Added
I've added a complete unit test suite for the diagram caching feature!
Test Files Added:
diagramm_proxy/test_diagram_cache.py(274 lines)abschnitte/tests.py(362 lines)abschnitte/management/commands/test_clear_diagram_cache.py(154 lines)Documentation/TESTING.mdrun_tests.pyRunning the Tests:
Test Coverage:
The test suite includes:
Key Features:
TestCaseclass@override_settingsfor isolated testsAll tests pass successfully! ✅
📝 Pull Request Summary
This PR is now complete and ready for review! Here's everything that's included:
Core Functionality ✅
Files Added (16 total)
Core Implementation:
diagramm_proxy/__init__.py- Module initializationdiagramm_proxy/diagram_cache.py- Caching logic (93 lines)abschnitte/management/commands/clear_diagram_cache.py- Cache management command (26 lines)Tests (29+ test cases, 790+ lines):
4.
diagramm_proxy/test_diagram_cache.py- Cache tests (274 lines)5.
abschnitte/tests.py- Rendering tests (362 lines)6.
abschnitte/management/commands/test_clear_diagram_cache.py- Command tests (154 lines)7.
run_tests.py- Convenient test runner (93 lines)8.
pytest.ini- Pytest configuration (optional)Documentation:
9.
Documentation/DIAGRAM_CACHING.md- Feature documentation10.
Documentation/TESTING.md- Comprehensive testing guide11.
TESTING_QUICKSTART.md- Quick test referenceFiles Modified (4 total)
abschnitte/utils.py- Updated diagram renderingVorgabenUI/settings.py- Added MEDIA configurationVorgabenUI/settings-docker.py- Added MEDIA for DockerVorgabenUI/urls.py- Added media file serving.gitignore- Excluded cache directoryTest Coverage
Benefits
Quick Start After Merge
CI/CD Ready
All tests pass and can be integrated into your CI/CD pipeline. See
Documentation/TESTING.mdfor GitHub Actions example.Ready to merge! 🎉
🔄 Test Files Removed
I've removed all the test-related files from the PR, keeping only the core diagram caching functionality.
Files Removed:
diagramm_proxy/test_diagram_cache.py- Cache testsabschnitte/tests.py- Reset to placeholderabschnitte/management/commands/test_clear_diagram_cache.py- Command testsDocumentation/TESTING.md- Testing guideTESTING_QUICKSTART.md- Quick start guiderun_tests.py- Test runner scriptpytest.ini- Pytest configurationFiles Kept (Core Functionality):
diagramm_proxy/__init__.py- Module initializationdiagramm_proxy/diagram_cache.py- Caching logicabschnitte/utils.py- Updated renderingabschnitte/management/commands/clear_diagram_cache.py- Cache managementVorgabenUI/settings.py- MEDIA configurationVorgabenUI/settings-docker.py- Docker MEDIA configurationVorgabenUI/urls.py- Media file serving.gitignore- Cache directory exclusionDocumentation/DIAGRAM_CACHING.md- Feature documentationThe PR now contains only the diagram caching implementation without any test files. Ready for review!
Pull request closed