Spaces:
Running
Running
sync: 193 file da Baida98/AI@a7016b3e (2026-08-27 20:07 UTC) [deploy-all]
#125
by Baida07 - opened
- api/database.py +2 -1
- api/performance_rum.py +2 -1
- main.py +1 -0
api/database.py
CHANGED
|
@@ -113,9 +113,10 @@ async def _pg_query(db_url: str, sql: str, params: list):
|
|
| 113 |
return {"ok": False, "error": "psycopg2 non installato. Aggiungi 'psycopg2-binary' a requirements.txt."}
|
| 114 |
|
| 115 |
def _run():
|
| 116 |
-
conn = psycopg2.connect(db_url)
|
| 117 |
try:
|
| 118 |
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
|
|
|
| 119 |
cur.execute(sql, params or None)
|
| 120 |
try:
|
| 121 |
rows = [dict(r) for r in cur.fetchmany(_MAX_ROWS)]
|
|
|
|
| 113 |
return {"ok": False, "error": "psycopg2 non installato. Aggiungi 'psycopg2-binary' a requirements.txt."}
|
| 114 |
|
| 115 |
def _run():
|
| 116 |
+
conn = psycopg2.connect(db_url, connect_timeout=5)
|
| 117 |
try:
|
| 118 |
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
| 119 |
+
cur.execute("SET statement_timeout = '5000ms'")
|
| 120 |
cur.execute(sql, params or None)
|
| 121 |
try:
|
| 122 |
rows = [dict(r) for r in cur.fetchmany(_MAX_ROWS)]
|
api/performance_rum.py
CHANGED
|
@@ -124,9 +124,10 @@ def _execute(sql: str, params: dict[str, Any], *, fetch: bool = False) -> list[d
|
|
| 124 |
import psycopg2
|
| 125 |
import psycopg2.extras
|
| 126 |
|
| 127 |
-
conn = psycopg2.connect(_db_url())
|
| 128 |
try:
|
| 129 |
with conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cur:
|
|
|
|
| 130 |
cur.execute(sql, params)
|
| 131 |
rows = [dict(row) for row in cur.fetchall()] if fetch else []
|
| 132 |
conn.commit()
|
|
|
|
| 124 |
import psycopg2
|
| 125 |
import psycopg2.extras
|
| 126 |
|
| 127 |
+
conn = psycopg2.connect(_db_url(), connect_timeout=5)
|
| 128 |
try:
|
| 129 |
with conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cur:
|
| 130 |
+
cur.execute("SET statement_timeout = '5000ms'")
|
| 131 |
cur.execute(sql, params)
|
| 132 |
rows = [dict(row) for row in cur.fetchall()] if fetch else []
|
| 133 |
conn.commit()
|
main.py
CHANGED
|
@@ -103,6 +103,7 @@ async def _run_auto_migration():
|
|
| 103 |
try:
|
| 104 |
conn = psycopg2.connect(f"postgresql://postgres:{db_pass}@{db_host}:{port}/postgres?sslmode=require", connect_timeout=5)
|
| 105 |
cur = conn.cursor()
|
|
|
|
| 106 |
cur.execute(sql)
|
| 107 |
conn.commit()
|
| 108 |
cur.close()
|
|
|
|
| 103 |
try:
|
| 104 |
conn = psycopg2.connect(f"postgresql://postgres:{db_pass}@{db_host}:{port}/postgres?sslmode=require", connect_timeout=5)
|
| 105 |
cur = conn.cursor()
|
| 106 |
+
cur.execute("SET statement_timeout = '5000ms'")
|
| 107 |
cur.execute(sql)
|
| 108 |
conn.commit()
|
| 109 |
cur.close()
|