use the latest used alias as recommendation
This commit is contained in:
parent
d58ab8c808
commit
a9e781da84
|
@ -1,5 +1,6 @@
|
||||||
from flask import jsonify, request, g
|
from flask import jsonify, request, g
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
|
from sqlalchemy import desc
|
||||||
|
|
||||||
from app.api.base import api_bp, verify_api_key
|
from app.api.base import api_bp, verify_api_key
|
||||||
from app.config import EMAIL_DOMAIN
|
from app.config import EMAIL_DOMAIN
|
||||||
|
@ -37,11 +38,16 @@ def options():
|
||||||
|
|
||||||
# recommendation alias if exist
|
# recommendation alias if exist
|
||||||
if hostname:
|
if hostname:
|
||||||
q = db.session.query(AliasUsedOn, GenEmail, User).filter(
|
# put the latest used alias first
|
||||||
|
q = (
|
||||||
|
db.session.query(AliasUsedOn, GenEmail, User)
|
||||||
|
.filter(
|
||||||
AliasUsedOn.gen_email_id == GenEmail.id,
|
AliasUsedOn.gen_email_id == GenEmail.id,
|
||||||
GenEmail.user_id == user.id,
|
GenEmail.user_id == user.id,
|
||||||
AliasUsedOn.hostname == hostname,
|
AliasUsedOn.hostname == hostname,
|
||||||
)
|
)
|
||||||
|
.order_by(desc(AliasUsedOn.created_at))
|
||||||
|
)
|
||||||
|
|
||||||
r = q.first()
|
r = q.first()
|
||||||
if r:
|
if r:
|
||||||
|
|
Loading…
Reference in a new issue