-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: optimize concurrency and resource utilization #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,13 +28,15 @@ | |||||
|
|
||||||
| # 🛡️ Configuración Maestra (abvetos.com) - Secrets moved to environment variables | ||||||
| SECRET_KEY = os.getenv("LVT_SECRET_KEY", "DEVELOPMENT_SECRET_DO_NOT_USE_IN_PROD") | ||||||
| SECRET_KEY_BYTES = SECRET_KEY.encode() # Pre-encoded for performance | ||||||
| PATENT = "PCT/EP2025/067317" | ||||||
|
|
||||||
| def verify_auth(user_id: str, token: str) -> bool: | ||||||
| try: | ||||||
| ts, sig = token.split('.') | ||||||
| if int(time.time()) - int(ts) > 600: return False # Ventana 10 min | ||||||
| expected = hmac.new(SECRET_KEY.encode(), f"{user_id}:{ts}".encode(), hashlib.sha256).hexdigest() | ||||||
| # Use pre-encoded key to save CPU cycles on every request | ||||||
| expected = hmac.new(SECRET_KEY_BYTES, f"{user_id}:{ts}".encode(), hashlib.sha256).hexdigest() | ||||||
| return hmac.compare_digest(sig, expected) | ||||||
| except: return False | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a bare
Suggested change
|
||||||
|
|
||||||
|
|
@@ -50,7 +52,7 @@ def calculate_fit(user_waist: float, item_id: str): | |||||
| return is_perfect, round(fit_index, 3), item | ||||||
|
|
||||||
| @app.post("/api/recommend") | ||||||
| async def recommend_garment(scan: UserScan, garment_id: str = "BALMAIN_SS26_SLIM"): | ||||||
| def recommend_garment(scan: UserScan, garment_id: str = "BALMAIN_SS26_SLIM"): | ||||||
| # 1. Seguridad y Handshake | ||||||
| if not verify_auth(scan.user_id, scan.token): | ||||||
| raise HTTPException(status_code=403, detail="Acceso restringido al búnker.") | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,4 +42,3 @@ class Garment(BaseModel): | |
| } | ||
| } | ||
|
|
||
| GARMENT_DB = list(SHOPIFY_INVENTORY.values()) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,9 @@ class TryOnYouBunker { | |||||||||||||||||
| this.selectedGarmentId = "BALMAIN_SS26_SLIM"; | ||||||||||||||||||
| this.version = "11.0.0"; | ||||||||||||||||||
| this.biometricAnalyzer = new MediaPipeBiometricAnalyzer(); | ||||||||||||||||||
| // Cache frequently accessed DOM elements | ||||||||||||||||||
| this.resultContainer = null; | ||||||||||||||||||
| this.resultText = null; | ||||||||||||||||||
| this.shopifyInventory = { | ||||||||||||||||||
| "BALMAIN_SS26_SLIM": { | ||||||||||||||||||
| "name": "Balmain Slim-Fit Jeans", | ||||||||||||||||||
|
|
@@ -57,6 +60,9 @@ class TryOnYouBunker { | |||||||||||||||||
| 'background: #C5A46D; color: #141619; font-weight: bold; padding: 2px 4px;', | ||||||||||||||||||
| 'background: #141619; color: #C5A46D; padding: 2px 4px;'); | ||||||||||||||||||
|
|
||||||||||||||||||
| this.resultContainer = document.getElementById('jules-result'); | ||||||||||||||||||
| this.resultText = document.getElementById('recommendation-text'); | ||||||||||||||||||
|
Comment on lines
+63
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caching DOM elements is a great performance enhancement. However, if
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| this.setupEventListeners(); | ||||||||||||||||||
| this.applyLuxuryTransitions(); | ||||||||||||||||||
| this.initializeBiometrics(); | ||||||||||||||||||
|
|
@@ -105,8 +111,8 @@ class TryOnYouBunker { | |||||||||||||||||
| const formData = new FormData(event.target); | ||||||||||||||||||
| const eventType = formData.get('event_type'); | ||||||||||||||||||
|
|
||||||||||||||||||
| const resultContainer = document.getElementById('jules-result'); | ||||||||||||||||||
| const resultText = document.getElementById('recommendation-text'); | ||||||||||||||||||
| const resultContainer = this.resultContainer; | ||||||||||||||||||
| const resultText = this.resultText; | ||||||||||||||||||
| const submitBtn = event.target.querySelector('button[type="submit"]'); | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
|
|
@@ -210,6 +216,8 @@ class TryOnYouBunker { | |||||||||||||||||
| if (entry.isIntersecting) { | ||||||||||||||||||
| entry.target.style.opacity = '1'; | ||||||||||||||||||
| entry.target.style.transform = 'translateY(0)'; | ||||||||||||||||||
| // Unobserve to save resources after animation is triggered | ||||||||||||||||||
| observer.unobserve(entry.target); | ||||||||||||||||||
| } | ||||||||||||||||||
| }); | ||||||||||||||||||
| }, { threshold: 0.1 }); | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a bare
exceptclause is generally discouraged. It catches all exceptions, including system-exiting exceptions likeSystemExitandKeyboardInterrupt, which can hide serious problems and make debugging difficult. It's better to catch specific exceptions that you expect might occur, or at leastexcept Exception:.