From 3525f685bbb8cf69cdc40ad424a87bee0b624268 Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 28 May 2026 14:38:29 -0700 Subject: [PATCH] Skip wasted discovery-section queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two related gates on the unified discovery sections: - PledgesDiscoverySection: the chronological useActions({ limit: 300 }) query only feeds the idle render branch (via idlePledges), but it was firing in active-search mode too. Active mode renders searchHits from useNip50Search, which never reads rawActions. On every keystroke that activates search we were burning a 300-event relay round-trip whose results went nowhere. Gate the query on !isSearching so the fetch happens only when the idle branch can actually consume it. - CampaignsDiscoverySection: align the featured-coords useCampaigns query's enabled flag with the pledges section's pattern. useCampaigns already short-circuits on an empty coordinates array, so this is purely about not creating an empty cache entry when moderators have curated nothing — but it removes a small asymmetry that would have made the next reviewer second-guess which pattern is intentional. --- src/components/discovery/CampaignsDiscoverySection.tsx | 6 +++++- src/components/discovery/PledgesDiscoverySection.tsx | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/discovery/CampaignsDiscoverySection.tsx b/src/components/discovery/CampaignsDiscoverySection.tsx index 00c469e5..0c941d60 100644 --- a/src/components/discovery/CampaignsDiscoverySection.tsx +++ b/src/components/discovery/CampaignsDiscoverySection.tsx @@ -124,7 +124,11 @@ export function CampaignsDiscoverySection({ const { data: featuredCampaigns } = useCampaigns({ coordinates: featuredCoords, limit: featuredCoords.length || 1, - enabled: moderationReady, + // Mirrors the pledges section's pattern: don't enable the query + // when there are no coords to fetch. `useCampaigns` already + // short-circuits internally on an empty `coordinates` array, so + // this is purely about not creating a meaningless cache entry. + enabled: moderationReady && featuredCoords.length > 0, }); const showHiddenValue = showHiddenProp?.value ?? false; diff --git a/src/components/discovery/PledgesDiscoverySection.tsx b/src/components/discovery/PledgesDiscoverySection.tsx index 24cd6afd..f9b29b80 100644 --- a/src/components/discovery/PledgesDiscoverySection.tsx +++ b/src/components/discovery/PledgesDiscoverySection.tsx @@ -123,9 +123,18 @@ export function PledgesDiscoverySection({ }, }); + // Chronological feed that backs the idle grid (and the + // featured-then-chronological fallback). Gated on `!isSearching` + // because the search branch renders `searchHits` instead and never + // reads `rawActions` / `actions` — leaving this query enabled during + // search burns a 300-event relay round-trip on every keystroke that + // activates the search view. The idle branch is the only consumer, + // and the idle branch only renders when `!isSearching`, so this + // gate strictly removes wasted work. const { data: rawActions, isLoading: actionsLoading } = useActions({ countryCode: filters.country, limit: 300, + enabled: !isSearching, }); const { data: pledgeModeration, isReady: pledgeModerationReady } =