ericjedha commited on
Commit
875aa26
·
verified ·
1 Parent(s): 20828a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -22,25 +22,29 @@ COLOR_SAVED = "#FFD700" # Or pour l'argent économisé
22
  # ========================== CONNEXION BASE DE DONNÉES ==========================
23
  @st.cache_resource
24
  def get_db_connection():
25
- """Connexion à Neon DB via Hugging Face Secret avec pool de connexions"""
26
  try:
27
  database_url = os.environ.get("NEON_DB_FRAUD_URL")
28
  if not database_url:
29
  st.error("❌ Variable NEON_DB_FRAUD_URL non trouvée dans les secrets Hugging Face")
30
  st.stop()
31
 
32
- # Options pour améliorer la stabilité avec Neon DB
33
  engine = create_engine(
34
- database_url,
35
- pool_pre_ping=True,
36
- pool_recycle=3600,
37
- connect_args={"connect_timeout": 10}
38
- )
 
 
 
39
  return engine
40
  except Exception as e:
41
  st.error(f"❌ Erreur de connexion à la base de données: {e}")
42
  st.stop()
43
 
 
44
  # ========================== REQUÊTES SQL OPTIMISÉES ==========================
45
  def load_all_data():
46
  """Charge toutes les transactions - APPELÉ SEULEMENT APRÈS CLIC SUR REFRESH"""
 
22
  # ========================== CONNEXION BASE DE DONNÉES ==========================
23
  @st.cache_resource
24
  def get_db_connection():
25
+ """Connexion directe à Neon DB (non-pooler, stable pour petit volume)"""
26
  try:
27
  database_url = os.environ.get("NEON_DB_FRAUD_URL")
28
  if not database_url:
29
  st.error("❌ Variable NEON_DB_FRAUD_URL non trouvée dans les secrets Hugging Face")
30
  st.stop()
31
 
32
+ # Connexion directe sans pooler autorise les options PostgreSQL
33
  engine = create_engine(
34
+ database_url,
35
+ pool_pre_ping=True,
36
+ pool_recycle=3600,
37
+ connect_args={
38
+ "connect_timeout": 10,
39
+ "options": "-c statement_timeout=30000"
40
+ }
41
+ )
42
  return engine
43
  except Exception as e:
44
  st.error(f"❌ Erreur de connexion à la base de données: {e}")
45
  st.stop()
46
 
47
+
48
  # ========================== REQUÊTES SQL OPTIMISÉES ==========================
49
  def load_all_data():
50
  """Charge toutes les transactions - APPELÉ SEULEMENT APRÈS CLIC SUR REFRESH"""