在我的应用程序中,我使用了flask-security来添加身份验证和授权主题。SQLAlchemy 也用作数据提供者(使用 MySQL 作为后端)。该应用程序运行良好。
然后,我做了一些 MySQL 跟踪,日志显示在应用程序请求的每个 URL 处,flask-security 库发送两个数据库查询:
select ... from user where user.id = 'the user identifier' select ... from role, roles_users ...我认为这是一个性能问题,我喜欢尽量减少这些查询。我不知道是否有我缺少的配置功能。
我想检查一个对象或变量是否是指定类类型的实例,但使用此类的名称,而不是其类型。像这样的东西:
class A: pass
class B(A): pass
class C(B): pass
c_inst = C()
# Not working, isinstance expects the type:
ok = isinstance(c_inst, 'A')
Run Code Online (Sandbox Code Playgroud)
还有其他选择吗?我想使用类名,因此 isinstance(c_inst, A)在这种情况下不可用。
我有这样的域类:
class Document {
String mime;
String name;
byte[] content;
static mapping = {
content lazy:true;
}
}
Run Code Online (Sandbox Code Playgroud)
我想在"内容"列中启用延迟加载,因为应用程序可以执行某些操作而无需访问此列.
但懒惰:真正的选择不起作用......任何想法或解决方法?