fix(proxy/utils.py): don't keep connecting to db if connection already established

This commit is contained in:
Krrish Dholakia 2024-01-03 17:43:44 +05:30
parent f2da345173
commit 469ae0a378
2 changed files with 7 additions and 3 deletions

View file

@ -1014,7 +1014,7 @@ async def startup_event():
) # start the background health check coroutine.
print_verbose(f"prisma client - {prisma_client}")
if prisma_client:
if prisma_client is not None:
await prisma_client.connect()
if prisma_client is not None and master_key is not None:

View file

@ -255,7 +255,7 @@ class PrismaClient:
)
## init logging object
self.proxy_logging_obj = proxy_logging_obj
self.connected = False
os.environ["DATABASE_URL"] = database_url
# Save the current working directory
original_dir = os.getcwd()
@ -505,7 +505,11 @@ class PrismaClient:
)
async def connect(self):
try:
if self.connected == False:
await self.db.connect()
self.connected = True
else:
return
except Exception as e:
asyncio.create_task(
self.proxy_logging_obj.failure_handler(original_exception=e)