Skip to content
FeaturesPricingAffiliateBlogHelpAboutContact
Get StartedSign In
Back to Blog
industry2026-05-2312 min read

My affiliate dashboard took 8 seconds to load — N+1 query fix (PR #644 V F4)

Matthias (30) Vienna-based food + restaurant-tech content creator @matthiaseats engaged Instagram + TikTok, 7 months thMenu affiliate ~100-130 monthly cafe + restaurant onboardings. Friday evening dashboard loaded in 12 seconds, tab switches 8-14 seconds each, Conversion Funnel + Per-Restaurant Performance + Top Referring Pages all painful. Matthias emailed support: "dashboard painfully slow, is this normal? Internet fine, other sites <1s." Support 3 wrong theory busted (bandwidth: 145 Mbps fine, mobile tether: not, D1 quota: Pro tier well under). 4th theory D1 query log: 240+ separate queries single page-load. Matthias 120 conversions = 1 SELECT + 120 restaurant queries + 120 commission queries = **241 sequential D1 queries**. D1 ~30ms × 241 = 7.2s sequential + parsing = 8-14s observed. Classic **N+1 anti-pattern** — programming-literature-old (Hibernate 2002 eager fetching, ActiveRecord 2005 includes(), EF Core Include) but production-friendly. thMenu code shipped early 2024 for ~20-50 conversion affiliates (3s tolerable). Heavy affiliates crossed threshold months later. **PR #644 batch V F4** fix: 241 → 3 batched queries: (1) SELECT conversions; (2) SELECT restaurants WHERE id IN (deduped ids); (3) SELECT commissions ROW_NUMBER OVER PARTITION BY conversion_id ORDER BY created_at DESC + filter rn=1; (4) JS-side Map merge restMap.get + commMap.get O(1). 3 queries × 30ms = ~90ms + parse + serialize = ~200ms. Dashboard 30s → 600ms, 40-70x speedup. Other tabs same pattern rewrite. Matthias Instagram story "thMenu fixed slowness, 40x faster" 8,500 views, organic affiliate uplift over next month. End-of-month commission EUR 890 (vs 620 previous month). Pattern: N+1 detection requires per-request query-count metrics + threshold alarms (>10 queries per request) + eager-load shared helper + code-review discipline flagging for-loop + query patterns. Production-friendly antipattern hidden at low data volumes until heavy users cross threshold.

th

thMenu Team

thmenu.com

Found this helpful? Share it.

X / TwitterLinkedIn