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
+4 -3
View File
@@ -9,6 +9,7 @@ Key rules:
- stripe_enabled() guard lets the app run with no keys in dev.
"""
from datetime import datetime, timedelta
from app.utils.time import utcnow
import stripe
from flask import current_app
from app.extensions import db
@@ -140,7 +141,7 @@ def activate_boost(user_id: int, listing_id: int, boost_type: str,
db.session.add(txn)
db.session.flush()
expires_at = datetime.utcnow() + timedelta(days=info["days"])
expires_at = utcnow() + timedelta(days=info["days"])
boost = Boost(listing_id=listing_id, user_id=user_id,
type=boost_type, expires_at=expires_at,
transaction_id=txn.id)
@@ -152,7 +153,7 @@ def activate_boost(user_id: int, listing_id: int, boost_type: str,
if boost_type == "featured":
listing.is_featured = True
if boost_type == "bump":
listing.bump_at = datetime.utcnow()
listing.bump_at = utcnow()
db.session.commit()
return boost
@@ -307,7 +308,7 @@ def _record_sub_transaction(user_id, session):
def expire_boosts() -> int:
"""Clear expired boosts and revert listing effects. Returns count."""
now = datetime.utcnow()
now = utcnow()
expired = Boost.query.filter(Boost.expires_at <= now).all()
n = 0
for boost in expired: