About SQLAlchemy all () query performance issues

Problem Description: When we can not use all () query, the first thing you should consider is the performance issue, queries all the data practices will increase the burden on the database server memory consumption while increasing the amount of the table if the query data in the database is huge, then this method will get a system crash can not be avoided especially when we have list_resource interface of restful style, then how can we do it?
Here Insert Picture Description
Ideas:
The first is possible to add a filter condition, or use the limit () offset () and limiting the number of data intervals, as we do list_resource interface, we try to use the tab showing the front end of
Here Insert Picture Description
a time when we use the method paginate are you still worried about whether it is lack of performance? Whether all the data first and then check out paging through it? Not tell you, for you are listed below the source code, the source code is the use of limit and offset it, so be careful that you do not have performance problems
Here Insert Picture Description
in addition to the effect of sqlalchemy also cache, query the same data multiple times in the same request when he would only query once, the latter will be the use of locally cached data,
of course, you might think the performance is not good enough, then you can use redis build a layer of cache (not discussed in detail here)

In addition, there are other third-party libraries to show pagination, but only after the results of the query page display, enumerated below

  1. paginate_sqlalchemy
    official document addresses https://pypi.org/project/paginate_sqlalchemy/
  2. paginate (not found an official document addresses, but using pip installed, import paginate can use)
    only need to use pip can be installed, with reference to the specific use of official documentation and source code examples which you can use
Released two original articles · won praise 0 · Views 50

Guess you like

Origin blog.csdn.net/weixin_45488755/article/details/104309837