From ab89c4d3f1ddf8bf35aef3525720b27e9378340e Mon Sep 17 00:00:00 2001 From: albertkun Date: Tue, 21 Nov 2023 02:11:25 -0800 Subject: [PATCH] feat: database and cache initialization refactor: sqlachlmy logs to `false` --- fastapi/app/database.py | 4 ++-- fastapi/app/main.py | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/fastapi/app/database.py b/fastapi/app/database.py index 9487ab2..87da73e 100644 --- a/fastapi/app/database.py +++ b/fastapi/app/database.py @@ -14,8 +14,8 @@ def create_async_uri(uri): return uri.replace('postgresql', 'postgresql+asyncpg') -engine = create_engine(Config.API_DB_URI, echo=True, poolclass=NullPool) -async_engine = create_async_engine(create_async_uri(Config.API_DB_URI), echo=True, poolclass=NullPool) +engine = create_engine(Config.API_DB_URI, echo=False, poolclass=NullPool) +async_engine = create_async_engine(create_async_uri(Config.API_DB_URI), echo=False, poolclass=NullPool) async_session = sessionmaker(async_engine, expire_on_commit=False, class_=AsyncSession) Session = sessionmaker(autocommit=False, autoflush=False, bind=engine) diff --git a/fastapi/app/main.py b/fastapi/app/main.py index e076bf4..80da2cd 100644 --- a/fastapi/app/main.py +++ b/fastapi/app/main.py @@ -849,9 +849,8 @@ async def get_all_routes(): @app.on_event("startup") async def startup_event(): try: - redis_pool = await aioredis.from_url(Config.REDIS_URL) - redis = RedisBackend(redis_pool) - FastAPICache.init(backend=redis, prefix="fastapi-cache") + crud.redis = await aioredis.from_url(Config.REDIS_URL) + FastAPICache.init(backend=crud.redis, prefix="fastapi-cache") uvicorn_access_logger = logging.getLogger("uvicorn.access") uvicorn_error_logger = logging.getLogger("uvicorn.error") logger = logging.getLogger("uvicorn.app") @@ -878,7 +877,6 @@ async def startup_event(): except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr) - app.add_middleware( CORSMiddleware, allow_origins=["*"],