Merge pull request #819 from simple-login/feature/optimize-query-time
optimize dashboard page: load custom domain using joinedload()
This commit is contained in:
commit
d4867dc524
|
@ -204,7 +204,7 @@ def get_alias_infos_with_pagination_v3(
|
|||
q = list(q.limit(page_limit).offset(page_id * page_size))
|
||||
|
||||
ret = []
|
||||
for alias, contact, email_log, custom_domain, nb_reply, nb_blocked, nb_forward in q:
|
||||
for alias, contact, email_log, nb_reply, nb_blocked, nb_forward in q:
|
||||
ret.append(
|
||||
AliasInfo(
|
||||
alias=alias,
|
||||
|
@ -215,7 +215,7 @@ def get_alias_infos_with_pagination_v3(
|
|||
nb_reply=nb_reply,
|
||||
latest_email_log=email_log,
|
||||
latest_contact=contact,
|
||||
custom_domain=custom_domain,
|
||||
custom_domain=alias.custom_domain,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -318,7 +318,7 @@ def get_alias_info_v3(user: User, alias_id: int) -> AliasInfo:
|
|||
q = construct_alias_query(user)
|
||||
q = q.filter(Alias.id == alias_id)
|
||||
|
||||
for alias, contact, email_log, custom_domain, nb_reply, nb_blocked, nb_forward in q:
|
||||
for alias, contact, email_log, nb_reply, nb_blocked, nb_forward in q:
|
||||
return AliasInfo(
|
||||
alias=alias,
|
||||
mailbox=alias.mailbox,
|
||||
|
@ -328,7 +328,7 @@ def get_alias_info_v3(user: User, alias_id: int) -> AliasInfo:
|
|||
nb_reply=nb_reply,
|
||||
latest_email_log=email_log,
|
||||
latest_contact=contact,
|
||||
custom_domain=custom_domain,
|
||||
custom_domain=alias.custom_domain,
|
||||
)
|
||||
|
||||
|
||||
|
@ -379,14 +379,13 @@ def construct_alias_query(user: User):
|
|||
Alias,
|
||||
Contact,
|
||||
EmailLog,
|
||||
CustomDomain,
|
||||
alias_activity_subquery.c.nb_reply,
|
||||
alias_activity_subquery.c.nb_blocked,
|
||||
alias_activity_subquery.c.nb_forward,
|
||||
)
|
||||
.options(joinedload(Alias.hibp_breaches))
|
||||
.options(joinedload(Alias.custom_domain))
|
||||
.join(Contact, Alias.id == Contact.alias_id, isouter=True)
|
||||
.join(CustomDomain, Alias.custom_domain_id == CustomDomain.id, isouter=True)
|
||||
.join(EmailLog, Contact.id == EmailLog.contact_id, isouter=True)
|
||||
.filter(Alias.id == alias_activity_subquery.c.id)
|
||||
.filter(Alias.id == alias_contact_subquery.c.id)
|
||||
|
|
|
@ -1160,7 +1160,7 @@ class Alias(Base, ModelMixin):
|
|||
enabled = sa.Column(sa.Boolean(), default=True, nullable=False)
|
||||
|
||||
custom_domain_id = sa.Column(
|
||||
sa.ForeignKey("custom_domain.id", ondelete="cascade"), nullable=True
|
||||
sa.ForeignKey("custom_domain.id", ondelete="cascade"), nullable=True, index=True
|
||||
)
|
||||
|
||||
custom_domain = orm.relationship("CustomDomain", foreign_keys=[custom_domain_id])
|
||||
|
@ -1172,7 +1172,7 @@ class Alias(Base, ModelMixin):
|
|||
|
||||
# to know whether an alias belongs to a directory
|
||||
directory_id = sa.Column(
|
||||
sa.ForeignKey("directory.id", ondelete="cascade"), nullable=True
|
||||
sa.ForeignKey("directory.id", ondelete="cascade"), nullable=True, index=True
|
||||
)
|
||||
|
||||
note = sa.Column(sa.Text, default=None, nullable=True)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 5047fcbd57c7
|
||||
Revises: 9282e982bc05
|
||||
Create Date: 2022-02-26 17:51:03.379676
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '5047fcbd57c7'
|
||||
down_revision = '9282e982bc05'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_index(op.f('ix_alias_custom_domain_id'), 'alias', ['custom_domain_id'], unique=False)
|
||||
op.create_index(op.f('ix_alias_directory_id'), 'alias', ['directory_id'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_alias_directory_id'), table_name='alias')
|
||||
op.drop_index(op.f('ix_alias_custom_domain_id'), table_name='alias')
|
||||
# ### end Alembic commands ###
|
|
@ -284,7 +284,7 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if alias_info.custom_domain and not alias_info.custom_domain.verified %}
|
||||
{% if alias.custom_domain and not alias.custom_domain.verified %}
|
||||
<span class="fa fa-warning text-warning" data-toggle="tooltip"
|
||||
title="Alias can't receive emails as its domain doesn't have MX records set up."></span>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in New Issue