Skip wasted discovery-section queries
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 } =
|
||||
|
||||
Reference in New Issue
Block a user