I'm currently working on developing API with FastAPI.
The API is for getting certain amount of data on a specific date from MariaDB.
I implemented this using FastAPI Pagination, but the it took 9 seconds to get a response.
Would there be other ways to improve performance?
I'm attaching a little background below:
- The current GET API URL
http://localhost:8080/images/{date}?{page=N}&{size=M} (e.g. http://localhost:8080/images/20211223?page=1&size=50)
- Table information
The table has about 10,000,000 rows, and here are a few lines of aggregated data. There is no index in this table, as of now. If needed, I'd add it!
- The current implementation
# get function part
@router.get('/{stnd_ymd}', response_model=Page[ResponseImage])
async def get_images(stnd_ymd: str):
image_list = Images.get_all(stnd_ymd=stnd_ymd, cnts_ty_cd="CT_IMAGE")
return paginate(image_list)
# about `get_all` function
def get_all(cls, session: Session = None, **kwargs):
sess = next(db.session()) if not session else session
query = sess.query(cls)
for key, val in kwargs.items():
col = getattr(cls, key)
query = query.filter(col == val)
result = query.all()
if not session:
sess.close()
return result
If there is any other information needed, please tell me!
Thanks,