Jul 13 - Optimize code

This commit is contained in:
2026-07-13 16:52:00 -04:00
parent 936d860342
commit 00a9ba7770
27 changed files with 141 additions and 208 deletions
+3 -2
View File
@@ -11,6 +11,7 @@ use the existing `attributes` JSON and a private `_notified` sub-key so no migra
is required. The key is prefixed with `_` to avoid colliding with user attributes.
"""
from datetime import datetime, timedelta
from app.utils.time import utcnow
from flask import current_app
from app.extensions import db
from app.models.listing import Listing
@@ -25,13 +26,13 @@ def _already_notified(listing, key: str) -> bool:
def _mark_notified(listing, key: str):
attrs = dict(listing.attributes or {})
attrs[key] = datetime.utcnow().isoformat()
attrs[key] = utcnow().isoformat()
listing.attributes = attrs
def warn_expiring(days: int = 3) -> int:
"""Send warning emails for listings expiring within `days` days. Returns count."""
now = datetime.utcnow()
now = utcnow()
window_end = now + timedelta(days=days)
soon = (Listing.query
.filter(Listing.status == ListingStatus.active,