fix blocking behavior

This commit is contained in:
lelo 2025-04-21 17:53:22 +00:00
parent c1ee80ce1d
commit 7a75a5868e
2 changed files with 8 additions and 4 deletions

10
app.py
View File

@ -1,3 +1,5 @@
import eventlet
eventlet.monkey_patch()
from flask import Flask, render_template, send_file, url_for, jsonify, request, session, send_from_directory, make_response, abort
import os
from PIL import Image, ImageOps
@ -256,13 +258,15 @@ def serve_file(subpath):
mime, _ = mimetypes.guess_type(full_path)
mime = mime or 'application/octet-stream'
is_cache_request = request.headers.get('X-Cache-Request') == 'true'
is_audio_get = mime.startswith('audio/') and request.method == 'GET'
ip_address = request.remote_addr
user_agent = request.headers.get('User-Agent')
# skip logging on cache hits or on audio GETs (per your rules)
do_log = not is_cache_request
if mime == 'audio/mpeg' and request.method != 'HEAD':
do_log = False
do_log = (
not is_cache_request # skip if upstream CDN asked us to cache
and not is_audio_get # skip audio GETs
)
# 3) Pick cache
if mime.startswith('audio/'):

View File

@ -40,7 +40,7 @@ services:
# Production-ready Gunicorn command with eventlet
command: >
sh -c "pip install -r requirements.txt &&
gunicorn --worker-class eventlet -w 4 -b 0.0.0.0:5000 app:app"
gunicorn --worker-class eventlet -w 1 -b 0.0.0.0:5000 app:app"
networks: