fix delete_inbound_sms_older_than_retention and dao_get_inbound_sms_by_id

This commit is contained in:
Kenneth Kehl
2024-10-17 13:52:25 -07:00
parent cfce20fb46
commit 3c3fb8eb3a

View File

@@ -193,7 +193,7 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(
LIMIT 50 OFFSET :page
"""
t2 = aliased(InboundSms)
q = (
stmt = (
db.session.query(InboundSms)
.outerjoin(
t2,
@@ -210,5 +210,18 @@ def dao_get_paginated_most_recent_inbound_sms_by_user_number_for_service(
)
.order_by(InboundSms.created_at.desc())
)
return q.paginate(page=page, per_page=current_app.config["PAGE_SIZE"])
offset = (page - 1) * current_app.config["PAGE_SIZE"]
limit = current_app.config["PAGE_SIZE"]
paginated_stmt = stmt.limit(limit).offset(offset)
result = db.session.execute(paginated_stmt).scalars().all()
total_count_stmt = (
select(func.count())
.select_from(InboundSms)
.filter(
t2.id == None, # noqa
InboundSms.service_id == service_id,
InboundSms.created_at >= midnight_n_days_ago(limit_days),
)
)
total_count = db.session.execute(total_count_stmt).scalar()
return {"items": result, "total_count": total_count}