-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第3章LocalProxy的用法问题 #20
Comments
@guyskk 我懂了,对我这个例子来说是可以的,但是是错误的用法,晚上我再来。先谢了,去上班。 |
@dongweiming
|
@guyskk g就是一个LocalProxy对象,直接用就好了 没必要再代理一次了 |
@dongweiming 也对,就是LocalStack这样实现太曲折了 |
我的例子类似于自己实现了一次 g ,展示了如何把user压入和推出栈 |
LocalProxy我是这样用,简化插件的编写(不需要写init_app方法),或者用于是不支持Flask工厂模式的库。不过这样会有一点性能损失。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/dongweiming/web_develop/blob/master/chapter3/section4/app_with_local_proxy.py#L19
在一个请求中,每次获取current_user的属性都会重新执行一次get_current_user,导致一次请求会多次查询数据库。
也就是说这样的语句
会导致查询2次数据库。
因为current_user是一个代理对象,我将上述代码简化,如下:
每次获取current_user的属性都会打印出“call”,也就是执行一次get_current_user。
The text was updated successfully, but these errors were encountered: