Skip to content

perf(trending): memoize campaign heuristic calculations - #882

Open
JemimahEkong wants to merge 1 commit into
Iris-IV:mainfrom
JemimahEkong:perf/memoize-trending-campaigns
Open

perf(trending): memoize campaign heuristic calculations#882
JemimahEkong wants to merge 1 commit into
Iris-IV:mainfrom
JemimahEkong:perf/memoize-trending-campaigns

Conversation

@JemimahEkong

Copy link
Copy Markdown
Contributor

Summary

Optimizes the Trending Campaigns hook by memoizing heuristic calculations to prevent unnecessary recomputation during unrelated component re-renders.

Closes #832

Changes

  • Updated src/hooks/useTrendingCampaigns.ts:

    • Wrapped getTrendingCampaigns(campaigns, limit) with useMemo.
    • Added dependencies for campaigns and limit.
    • Preserved existing trending score calculations and ranking behavior.
  • Added src/__tests__/hooks/useTrendingCampaigns.test.tsx:

    • Verified trending order remains unchanged.
    • Added coverage for memoization behavior.
    • Confirmed recomputation occurs when campaigns data or limit changes.
    • Covered loading, error, and refetch passthrough behavior.

Validation

  • ✅ All 35 hook tests passing across 9 suites.
  • ✅ All 12 trending-related tests passing.
  • ✅ No changes to trending scoring factors or ranking logic.
  • ✅ Only computation frequency was optimized.

Notes

This change only improves performance by avoiding repeated heuristic calculations when the campaigns reference and limit remain unchanged. No user-facing behavior or trending results are modified.

@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@JemimahEkong Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] useTrendingCampaigns recomputes trendingHeuristic on every render instead of memoizing by campaign list identity

2 participants