order alias by most recent ones

This commit is contained in:
Son NK 2020-01-23 20:19:58 +01:00
parent d6020d5fa0
commit 8c14c25cec

View file

@ -148,10 +148,14 @@ def get_alias_info(user_id, query=None, highlight_gen_email_id=None) -> [AliasIn
query = query.strip().lower() query = query.strip().lower()
aliases = {} # dict of alias and AliasInfo aliases = {} # dict of alias and AliasInfo
q = db.session.query(GenEmail, ForwardEmail, ForwardEmailLog).filter( q = (
GenEmail.user_id == user_id, db.session.query(GenEmail, ForwardEmail, ForwardEmailLog)
GenEmail.id == ForwardEmail.gen_email_id, .filter(
ForwardEmail.id == ForwardEmailLog.forward_id, GenEmail.user_id == user_id,
GenEmail.id == ForwardEmail.gen_email_id,
ForwardEmail.id == ForwardEmailLog.forward_id,
)
.order_by(GenEmail.created_at.desc())
) )
if query: if query:
@ -180,7 +184,7 @@ def get_alias_info(user_id, query=None, highlight_gen_email_id=None) -> [AliasIn
db.session.query(GenEmail) db.session.query(GenEmail)
.filter(GenEmail.email.notin_(aliases.keys())) .filter(GenEmail.email.notin_(aliases.keys()))
.filter(GenEmail.user_id == user_id) .filter(GenEmail.user_id == user_id)
) ).order_by(GenEmail.created_at.desc())
if query: if query:
q = q.filter(GenEmail.email.contains(query)) q = q.filter(GenEmail.email.contains(query))