From 207c5028ae3176a9ca37790f6bc7ef661be216e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hamitcan=20MALKO=C3=87?= Date: Mon, 9 Nov 2026 19:28:43 +0300 Subject: [PATCH 1/6] change supabase pool to db pool --- backend/app/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 00734b2fa3..18879c5259 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -92,12 +92,12 @@ async def lifespan(app: FastAPI): # Initialize Supabase connection pool try: - from .core.supabase_connection_pool import supabase_pool + from .core.database_pool import db_pool - await supabase_pool.initialize() - logger.info("✅ Supabase connection pool initialized") + await db_pool.initialize() + logger.info("✅ Database connection pool initialized") except Exception as e: - logger.error(f"❌ Supabase connection pool initialization failed: {e}") + logger.error(f"❌ Database connection pool initialization failed: {e}") # Continue startup - fallback to direct connections # Initialize Redis connection with timeout From a8a4d7c9202e9b314d33e4cb265a570b2efa0776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hamitcan=20MALKO=C3=87?= Date: Mon, 9 Nov 2026 19:29:06 +0300 Subject: [PATCH 2/6] fix db pool url connection and aysnc context manager --- backend/app/core/database_pool.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/core/database_pool.py b/backend/app/core/database_pool.py index d638dfcfe3..5d5ccf4ee3 100644 --- a/backend/app/core/database_pool.py +++ b/backend/app/core/database_pool.py @@ -15,11 +15,11 @@ async def initialize(self): """Initialize database connection pool""" try: # Create async engine with connection pooling - database_url = f"postgresql+asyncpg://{settings.supabase_db_user}:{settings.supabase_db_password}@{settings.supabase_db_host}:{settings.supabase_db_port}/{settings.supabase_db_name}" - + database_url = settings.database_url + self.engine = create_async_engine( database_url, - poolclass=QueuePool, + # poolclass=QueuePool, pool_size=20, # Number of connections to maintain max_overflow=30, # Additional connections when needed pool_pre_ping=True, # Validate connections @@ -56,5 +56,5 @@ async def get_session(self) -> AsyncSession: async def get_db_session() -> AsyncSession: """Dependency to get database session""" - async with db_pool.get_session() as session: + async with (await db_pool.get_session()) as session: yield session From 0f9b277fd3f39e79a302dd99b1899b92e5a4f325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hamitcan=20MALKO=C3=87?= Date: Mon, 9 Nov 2026 19:29:32 +0300 Subject: [PATCH 3/6] use asyncpg as connection string --- backend/app/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/config.py b/backend/app/config.py index 7eab778f75..d0c06fbd75 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -9,7 +9,7 @@ class Settings(BaseSettings): # Core settings - database_url: str = "postgresql://postgres:postgres@db:5432/propertyflow" + database_url: str = "postgresql+asyncpg://postgres:postgres@db:5432/propertyflow" redis_url: str = "redis://redis:6379/0" secret_key: str = "debug_challenge_secret" From 837cbc6f8fe0f38925823941dde8787fc1613be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hamitcan=20MALKO=C3=87?= Date: Mon, 9 Nov 2026 19:29:43 +0300 Subject: [PATCH 4/6] updating the requirements --- backend/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 6b777d2aaa..f16fe9e1af 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -9,6 +9,7 @@ lz4 orjson Pillow==10.4.0 psycopg2-binary +psycopg pydantic-settings pydantic[email] pyhumps==3.8.0 @@ -18,7 +19,7 @@ pytz redis>=5.0.0 requests sendgrid -sqlalchemy>=2.0.0 +sqlalchemy[asyncio]>=2.0.0 supabase tenacity>=8.0.0 uvicorn[standard] From 753c025c76e73f622a95c19f709cd15bcf82eda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hamitcan=20MALKO=C3=87?= Date: Mon, 9 Nov 2026 19:29:59 +0300 Subject: [PATCH 5/6] apply context manager changes --- backend/app/services/reservations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/services/reservations.py b/backend/app/services/reservations.py index 384bd00abe..85745c5d63 100644 --- a/backend/app/services/reservations.py +++ b/backend/app/services/reservations.py @@ -44,7 +44,7 @@ async def calculate_total_revenue(property_id: str, tenant_id: str) -> Dict[str, await db_pool.initialize() if db_pool.session_factory: - async with db_pool.get_session() as session: + async with (await db_pool.get_session()) as session: # Use SQLAlchemy text for raw SQL from sqlalchemy import text From 7757d325cc2708e6415e61d92366e7d0e35cabfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hamitcan=20MALKO=C3=87?= Date: Mon, 9 Nov 2026 19:30:12 +0300 Subject: [PATCH 6/6] adding tenant id in cache key --- backend/app/services/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/services/cache.py b/backend/app/services/cache.py index b81474957f..8c03feff79 100644 --- a/backend/app/services/cache.py +++ b/backend/app/services/cache.py @@ -10,7 +10,7 @@ async def get_revenue_summary(property_id: str, tenant_id: str) -> Dict[str, Any """ Fetches revenue summary, utilizing caching to improve performance. """ - cache_key = f"revenue:{property_id}" + cache_key = f"revenue:{property_id}:{tenant_id}" # Try to get from cache cached = await redis_client.get(cache_key)