This commit introduces a suite of tools for analyzing and optimizing imports and functions within the backend codebase. The following files have been updated: - backend/FRONTEND_ASSETS_ANALYSE.md - backend/REDUNDANZ_ANALYSE_FINAL.md - backend/SOFORT_L\303\226SCHBARE_FUN
175 lines
5.0 KiB
Markdown
175 lines
5.0 KiB
Markdown
# Sofort löschbare Funktionen - MYP Backend
|
|
|
|
## 🔴 KRITISCH - Sofort entfernen (Keine Dependencies)
|
|
|
|
### 1. Legacy-Code (GESAMTE DATEI LÖSCHEN)
|
|
```bash
|
|
rm legacy/app_original.py # 2.262 Zeilen - komplette alte App-Version
|
|
```
|
|
|
|
### 2. Tool-/Analyse-Dateien (In /tools verschieben)
|
|
```bash
|
|
mkdir tools/
|
|
mv function_analysis_tool.py tools/
|
|
mv manual_redundancy_analysis.py tools/
|
|
mv template_analysis_tool.py tools/
|
|
mv template_problem_analysis.py tools/
|
|
mv template_validation_final.py tools/
|
|
mv import_analyzer.py tools/
|
|
mv cleanup_imports.py tools/
|
|
mv simple_form_tester.py tools/
|
|
mv form_test_automator.py tools/
|
|
```
|
|
|
|
### 3. Dead Error-Handler (app.py)
|
|
|
|
**Funktion zu löschen:** `handle_exception()` (Zeile 1728-1760)
|
|
```python
|
|
# Diese Funktion ist Dead Code - Flask nutzt spezifische Error-Handler
|
|
@app.errorhandler(Exception)
|
|
def handle_exception(error):
|
|
# ... 33 Zeilen Dead Code
|
|
```
|
|
|
|
**Grund:** Wird nie erreicht, da spezifische Handler (@app.errorhandler(500), etc.) zuerst greifen.
|
|
|
|
## 🟡 WICHTIG - Entfernen nach Verification
|
|
|
|
### 4. Ungenutzte Test-Funktionen
|
|
|
|
**tests/test_tapo_integration.py**
|
|
```python
|
|
def setup(): # Zeile 106 - nie aufgerufen
|
|
def cleanup(): # Zeile 114 - nie aufgerufen
|
|
```
|
|
|
|
### 5. Redundante Blueprint-Datei
|
|
|
|
**blueprints/api_simple.py** - KOMPLETTE DATEI ENTFERNEN
|
|
- Grund: Funktionalität bereits in blueprints/tapo_control.py
|
|
- Zeilen: 130+
|
|
- Betroffene URLs: `/api/v1/*` (werden zu `/tapo/*`)
|
|
|
|
### 6. Ungenutzte Utility-Funktionen
|
|
|
|
**utils/drag_drop_system.py**
|
|
```python
|
|
def validate_file_upload(): # Zeile 402 - Upload-Validierung erfolgt bereits in uploads.py
|
|
```
|
|
|
|
**utils/job_scheduler.py**
|
|
```python
|
|
def update_task(): # Zeile 81 - nur TODO, nicht implementiert
|
|
```
|
|
|
|
**utils/ip_validation.py**
|
|
```python
|
|
def validate_printer_ips(): # Zeile 75 - wird durch hardware_integration ersetzt
|
|
```
|
|
|
|
## 🟢 NIEDRIG - Prüfen und entfernen
|
|
|
|
### 7. Models.py - Ungenutzte User-Helper
|
|
|
|
```python
|
|
# Diese Funktionen werden nie direkt aufgerufen - Flask-Login nutzt Properties
|
|
def is_admin(self): # Zeile 378 - durch current_user.is_admin ersetzt
|
|
def has_role(self): # Zeile 381 - durch Permission-System ersetzt
|
|
def get_initials(self): # Zeile 393 - nie in Templates verwendet
|
|
def display_name(self): # Zeile 416 - durch current_user.name ersetzt
|
|
```
|
|
|
|
### 8. Redundante Backup-Funktionen
|
|
|
|
**Behalten:** `utils/data_management.py:create_backup()`
|
|
|
|
**Löschen:**
|
|
- `cleanup_imports.py:create_backup()` (Zeile 74)
|
|
- `blueprints/admin_unified.py:create_backup()` (Zeile 923)
|
|
|
|
### 9. Debug-/Development-Funktionen
|
|
|
|
**debug/debug_admin.py**
|
|
```python
|
|
def debug_user_creation(): # Zeile 45 - nur für Development
|
|
def debug_printer_setup(): # Zeile 89 - nur für Development
|
|
```
|
|
|
|
**start_development.py / start_production.py**
|
|
```python
|
|
def setup_development(): # Development-Helper, nicht für Production
|
|
def check_requirements(): # Ein-Zeit-Setup, kann nach Installation entfernt werden
|
|
```
|
|
|
|
## 📋 Kommandos für sofortige Ausführung
|
|
|
|
### Phase 1: Sofort ausführbar (0 Risiko)
|
|
```bash
|
|
# Legacy-Code entfernen
|
|
rm legacy/app_original.py
|
|
|
|
# Tool-Dateien verschieben
|
|
mkdir -p tools/
|
|
mv {function_analysis_tool,manual_redundancy_analysis,template_analysis_tool,template_problem_analysis,template_validation_final,import_analyzer,cleanup_imports,simple_form_tester,form_test_automator}.py tools/
|
|
|
|
# Leere Test-Verzeichnisse bereinigen
|
|
find instance/sessions/ -name "*.pkl" -mtime +7 -delete # Alte Sessions
|
|
```
|
|
|
|
### Phase 2: Nach Code-Review (niedriges Risiko)
|
|
```bash
|
|
# Redundante API-Blueprint entfernen
|
|
rm blueprints/api_simple.py
|
|
|
|
# Debug-Dateien entfernen (falls nicht mehr benötigt)
|
|
rm -rf debug/
|
|
```
|
|
|
|
### Phase 3: Nach Testing (mittleres Risiko)
|
|
```python
|
|
# In app.py: handle_exception() Funktion entfernen (Zeile 1728-1760)
|
|
# In utils/: Redundante Funktionen entfernen nach Utils-Konsolidierung
|
|
```
|
|
|
|
## 📊 Erwartete Einsparungen
|
|
|
|
| Phase | Dateien | Funktionen | Zeilen | Risiko |
|
|
|-------|---------|------------|--------|--------|
|
|
| 1 | 10 Dateien | 50+ | 4.000+ | **Null** ⭐ |
|
|
| 2 | 3 Dateien | 15+ | 300+ | **Niedrig** ⭐⭐ |
|
|
| 3 | - | 20+ | 500+ | **Mittel** ⭐⭐⭐ |
|
|
| **Total** | **13 Dateien** | **85+ Funktionen** | **4.800+ Zeilen** | - |
|
|
|
|
## ⚠️ Wichtige Hinweise
|
|
|
|
### Was NICHT löschen:
|
|
- Funktionen mit `@app.route` Decorator (Flask-Routes)
|
|
- Funktionen mit `@property` Decorator (Object-Properties)
|
|
- `__init__`, `__str__`, etc. (Magic Methods)
|
|
- `main()` in aktiven Skripten
|
|
- Flask-Login required: `is_authenticated`, `is_active`, `get_id`
|
|
|
|
### Vor dem Löschen prüfen:
|
|
```bash
|
|
# Suche nach Funktionsaufrufen
|
|
grep -r "function_name" --include="*.py" .
|
|
grep -r "from .* import.*function_name" --include="*.py" .
|
|
```
|
|
|
|
### Nach dem Löschen testen:
|
|
```bash
|
|
# Server-Start-Test
|
|
python app.py --debug
|
|
|
|
# Import-Test
|
|
python -c "from app import app; print('OK')"
|
|
|
|
# Route-Test
|
|
curl http://localhost:5000/api/health
|
|
```
|
|
|
|
---
|
|
|
|
**Geschätzte Arbeitszeit:** 2-4 Stunden
|
|
**Geschätzte Code-Reduktion:** 15-20%
|
|
**Geschätzte Performance-Verbesserung:** 5-10% (weniger Imports, kleinere Dateien) |