Skip to content

Commit

Permalink
Merge pull request #412 from LACMTA:dev
Browse files Browse the repository at this point in the history
Update database and cache initialization
  • Loading branch information
albertkun authored Nov 21, 2023
2 parents 0c34103 + 4c2288a commit 474d0e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fastapi/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions fastapi/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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=["*"],
Expand Down

0 comments on commit 474d0e2

Please sign in to comment.