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
+7 -4
View File
@@ -10,14 +10,17 @@ moderators can spot scraping attempts.
"""
import re
from datetime import datetime
from app.utils.time import utcnow
from app.models.enums import TrustTier
from app.services.settings import get_setting
# patterns
_PHONE_RE = re.compile(
r"(\+?1[\s\-.]?)?"
r"(\(?\d{3}\)?[\s\-.])"
r"\d{3}[\s\-.]\d{4}"
r"(?<!\d)" # not mid-way through a longer digit run
r"(?:\+?1[\s\-.]?)?" # optional country code
r"\(?\d{3}\)?[\s\-.]?" # area code — separators now optional
r"\d{3}[\s\-.]?\d{4}" # so 5551234567 is caught, not just 555-123-4567
r"(?!\d)"
)
_EMAIL_RE = re.compile(r"[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}")
_URL_RE = re.compile(r"https?://\S+|www\.\S+", re.I)
@@ -32,7 +35,7 @@ def contact_revealed(user) -> bool:
return False
gate_days = get_setting("new_user_trust_gate_days", 0)
if gate_days and user.created_at:
if (datetime.utcnow() - user.created_at).days < gate_days:
if (utcnow() - user.created_at).days < gate_days:
return False
return True