修复网站 API 阻塞与积分同步问题
- uvicorn 改用 import string 格式启动 4 workers,防止数据采集阻塞 event loop - prewarm 去掉 --force-refresh,仅依赖缓存预热避免每 5 分钟全量采集 - 积分变动时同步写入 Supabase user_metadata,避免前端回退路径失败时显示 0 积分 - /api/auth/me 积分解析增加 Supabase email 回退路径
This commit is contained in:
+6
-1
@@ -35,4 +35,9 @@ __all__ = [
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
uvicorn.run(
|
||||
"web.app:app",
|
||||
host="0.0.0.0",
|
||||
port=8000,
|
||||
workers=int(os.getenv("UVICORN_WORKERS", "4")),
|
||||
)
|
||||
|
||||
+21
-11
@@ -239,19 +239,29 @@ def _resolve_auth_points(request: Request) -> int:
|
||||
points = max(0, int(raw_points or 0))
|
||||
except Exception:
|
||||
points = 0
|
||||
if points > 0:
|
||||
return points
|
||||
|
||||
user_id = str(getattr(request.state, "auth_user_id", "") or "").strip()
|
||||
if not user_id:
|
||||
return points
|
||||
try:
|
||||
db_points = _account_db.get_points_by_supabase_user_id(user_id)
|
||||
if db_points > points:
|
||||
request.state.auth_points = db_points
|
||||
return db_points
|
||||
except Exception as exc:
|
||||
logger.warning(f"auth points fallback failed user_id={user_id}: {exc}")
|
||||
|
||||
if user_id:
|
||||
try:
|
||||
db_points = _account_db.get_points_by_supabase_user_id(user_id)
|
||||
if db_points > points:
|
||||
request.state.auth_points = db_points
|
||||
points = db_points
|
||||
except Exception as exc:
|
||||
logger.warning(f"auth points fallback failed user_id={user_id}: {exc}")
|
||||
|
||||
if points <= 0:
|
||||
email = str(getattr(request.state, "auth_email", "") or "").strip().lower()
|
||||
if email:
|
||||
try:
|
||||
email_points = _account_db.get_points_by_supabase_email(email)
|
||||
if email_points > points:
|
||||
request.state.auth_points = email_points
|
||||
points = email_points
|
||||
except Exception as exc:
|
||||
logger.warning(f"auth points email fallback failed email={email}: {exc}")
|
||||
|
||||
return points
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user