当前位置:网站首页>19. Optimized database query of tornado project

19. Optimized database query of tornado project

2022-06-12 03:41:00 Solitary cold person

The project has been basically completed , This article will optimize the database query in the project .
Review the project , stay /utils/account.py The file contains many query operations for the database , These database query operations all rely on session, This session From the modles/account.py from modles/db.py The DBsession Instantiation .
So how to optimize it ?
About database related operations , It is obvious that a large number of database related operations will occur after the user logs in , Moreover, the user authentication function was added after the user login function was realized .
So based on this , Optimization has a direction , We can authenticate users ( namely main.py Medium AuthBaseHandler class ) At the same time, connect and close the database .
see 【tornado Official Chinese documents 】, We found the implementation method in the following screenshot , Know our user authentication AuthBaseHandler Class also inherits RequestHandler class ! So we add the following to the user authentication class 3 and 5 Two methods , Automatically establish and close the connection to the database !
 Insert picture description here

1. restructure session Use

  • ReuestHandler Of prepare and on_finish Use :
class 
原网站

版权声明
本文为[Solitary cold person]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120334241118.html