Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(next): reduce getNavPrefs calls from 3 to 1 per page load #11318

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

AlessioGr
Copy link
Member

Previously, we were calling getNavPrefs (a payload.find call) three times for every single page load.

This PR:

  1. Ensures that getNavPrefs is called only once per page load, reducing two unnecessary payload.find calls every time a page is loaded or navigated to.
  2. Adds pagination: false to the payload.find call, making it more efficient and improving performance.

How?

We were using React's cache to ensure that navigation preferences (getNavPrefs) were fetched only once per request. However, this wasn't working as expected because the first argument of getNavPrefs was an object. Each time it was called, a new object reference was passed, preventing React from caching it properly.

To fix this, this PR ensures that only primitive values are used as arguments for caching, following best practices and making the cache function work as intended.

@AlessioGr AlessioGr enabled auto-merge (squash) February 21, 2025 04:57
@AlessioGr AlessioGr disabled auto-merge February 21, 2025 04:58
@AlessioGr AlessioGr changed the title perf(next): ensure getNavPrefs is called 3x less perf(next): reduce getNavPrefs calls from 3 to 1 per page load Feb 21, 2025
@AlessioGr AlessioGr enabled auto-merge (squash) February 21, 2025 04:58
@AlessioGr AlessioGr merged commit c7c5018 into main Feb 21, 2025
76 checks passed
@AlessioGr AlessioGr deleted the perf/getNavPrefs branch February 21, 2025 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant