feat: Enhance home route to filter threads requiring replies and waiting over an hour
This commit is contained in:
+13
-5
@@ -55,7 +55,7 @@ def home(
|
|||||||
account: str | None = None,
|
account: str | None = None,
|
||||||
alerts_processed: int | None = None,
|
alerts_processed: int | None = None,
|
||||||
):
|
):
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
|
||||||
@@ -69,15 +69,23 @@ def home(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Main query joining threads with their latest message dates
|
# Main query joining threads with their latest message dates
|
||||||
q = (
|
q = db.query(Thread, latest_message_subq.c.latest_message_date).outerjoin(
|
||||||
db.query(Thread, latest_message_subq.c.latest_message_date)
|
latest_message_subq, Thread.id == latest_message_subq.c.thread_id
|
||||||
.outerjoin(latest_message_subq, Thread.id == latest_message_subq.c.thread_id)
|
)
|
||||||
.order_by(latest_message_subq.c.latest_message_date.desc().nulls_last())
|
|
||||||
|
# Only include threads that currently require a reply and have been waiting >= 1 hour
|
||||||
|
cutoff = datetime.utcnow() - timedelta(hours=1)
|
||||||
|
q = q.filter(
|
||||||
|
Thread.requires_reply.is_(True),
|
||||||
|
latest_message_subq.c.latest_message_date <= cutoff,
|
||||||
)
|
)
|
||||||
|
|
||||||
if account:
|
if account:
|
||||||
q = q.filter(Thread.account_email == account.lower())
|
q = q.filter(Thread.account_email == account.lower())
|
||||||
|
|
||||||
|
# Order by most recently updated (still respecting the cutoff filter)
|
||||||
|
q = q.order_by(latest_message_subq.c.latest_message_date.desc().nulls_last())
|
||||||
|
|
||||||
results = q.limit(100).all()
|
results = q.limit(100).all()
|
||||||
|
|
||||||
# Create threads with additional info including sequential frontend ID and formatted latest message date
|
# Create threads with additional info including sequential frontend ID and formatted latest message date
|
||||||
|
|||||||
Reference in New Issue
Block a user