浏览代码

lazy load alias._mailboxes and alias.mailbox

Son NK 5 年之前
父节点
当前提交
ff1aa72b1d
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      app/models.py

+ 3 - 2
app/models.py

@@ -10,6 +10,7 @@ from flask import url_for
 from flask_login import UserMixin
 from sqlalchemy import text, desc, CheckConstraint
 from sqlalchemy.exc import IntegrityError
+from sqlalchemy.orm import joinedload
 from sqlalchemy_utils import ArrowType
 
 from app import s3
@@ -638,10 +639,10 @@ class Alias(db.Model, ModelMixin):
 
     # prefix _ to avoid this object being used accidentally.
     # To have the list of all mailboxes, should use AliasInfo instead
-    _mailboxes = db.relationship("Mailbox", secondary="alias_mailbox")
+    _mailboxes = db.relationship("Mailbox", secondary="alias_mailbox", lazy="joined")
 
     user = db.relationship(User)
-    mailbox = db.relationship("Mailbox")
+    mailbox = db.relationship("Mailbox", lazy="joined")
 
     @property
     def mailboxes(self):