fix: smart routing in Browse — enrichment filters use /api/enriched, discovery uses /api/domains

Root cause: loadDomains() always hit /api/domains (DuckDB 72M rows) and filtered
niche/site_type/prescreen_status client-side on a random page of 100 domains —
virtually none had been classified, so Live+Beauty+Ecommerce always returned 0.

- loadDomains() now routes to /api/enriched when any enrichment filter is active
  (prescreen_status, niche, site_type, country) — all filters are server-side SQLite
- Falls back to /api/domains only when no enrichment filters are set (discovery mode)
- alpha_only and no_sld supported in both modes:
  - DuckDB: existing regex support
  - SQLite: LIKE patterns (no hyphens/digits) + dot-count (no SLD)
- Add alpha_only/no_sld params to /api/enriched endpoint and get_enriched()
- Fix stale d.classified reference in prescreenOne toast

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 08:53:54 +02:00
parent daccb99a0c
commit 2f0959b8e8
3 changed files with 33 additions and 10 deletions

View File

@@ -336,6 +336,7 @@ async def get_enriched(min_score=0, cms=None, country=None, kit_digital=None,
ai_only=False, lead_quality=None,
prescreen_status=None, niche=None, site_type=None,
keyword=None, tld=None,
alpha_only=False, no_sld=False,
page=1, limit=100):
offset = (page - 1) * limit
conditions = ["score >= ?"]
@@ -378,6 +379,17 @@ async def get_enriched(min_score=0, cms=None, country=None, kit_digital=None,
tld_clean = tld.lower().lstrip(".")
conditions.append("LOWER(domain) LIKE ?")
params.append(f"%.{tld_clean}")
if alpha_only:
# No hyphens, no digits anywhere in the domain name
conditions.append(
"domain NOT LIKE '%-%' AND domain NOT LIKE '%0%' AND domain NOT LIKE '%1%'"
" AND domain NOT LIKE '%2%' AND domain NOT LIKE '%3%' AND domain NOT LIKE '%4%'"
" AND domain NOT LIKE '%5%' AND domain NOT LIKE '%6%' AND domain NOT LIKE '%7%'"
" AND domain NOT LIKE '%8%' AND domain NOT LIKE '%9%'"
)
if no_sld:
# Exactly one dot → only name.tld, excludes shop.com.es style
conditions.append("(LENGTH(domain) - LENGTH(REPLACE(domain, '.', ''))) = 1")
where = "WHERE " + " AND ".join(conditions)
async with aiosqlite.connect(SQLITE_PATH, timeout=30) as db:
db.row_factory = aiosqlite.Row