Skip to content

feat(useProject): Create a hook to fetch individual projects and move away from the ProjectStore #68038

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

Closed
wants to merge 1 commit into from

Conversation

ryan953
Copy link
Member

@ryan953 ryan953 commented Apr 1, 2024

This first appeared in #66511. Trouble with that PR is the useAllProjectsOptions idea in there might not be great, so I wanted to skip that business for now, land what we can and come back to it after.

In order to move away from the pre-populated ProjectStore and useProjects() we need something else to move into. Why? We want to get rid of the pre-populated ProjectStore because it slows down every initial pageload by fetching every single project within an org. Not all orgs are needed on each page. useProjects() is the hook we us most often to interact with that store, but the trouble with useProjects() is that while it does return fetching: boolean, no callsites actually check the value. So if we were were to stop pre-populating the store, pages all over could look weird or throw because projects are not fetched.

So we need to update each callsite to check that fetching value before reading the project value. If we're going to touch each callsite then we might as well change out the backend so it's not ProjectStore anymore, this is where useProject() (singular now, not plural) comes in. By using a different method name we create an easy way to verify that a given callsite is checking isFetching or not, calls to the new method must do the check!

Related to #65949

@ryan953 ryan953 requested a review from a team as a code owner April 1, 2024 21:18
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 1, 2024
@ryan953 ryan953 requested review from a team, scttcper and davidenwang April 1, 2024 21:18
}, [id, slug, byIdCache, bySlugCache]);

const lookupId = id ?? slug;
return lookupId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this just returns the project data, but shouldn't it also return isLoading and isError?

if (bySlugCache.data?.[slug]) {
bySlugCache.buffer([`slug:${slug}`]);
} else {
bySlugCache.buffer([`slug:${slug}`]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the same as the line above it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh. I ripped out some stuff from that other PR, kept the wrong stuff!

responseReducer: useMemo(() => makeResponseReducer('id'), []),
});

const bySlugCache = useAggregatedQueryKeys<AggQueryKey, ProjectStore>({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on this, but I wonder if we should split this into two hooks useProjectById and useProjectBySlug to avoid having to deal with two separate caches

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do end up splitting this into two hooks i'd vouch for splitting the useTeamsById hook into useTeamsById + useTeamsBySlug for consistency

@getsantry
Copy link
Contributor

getsantry bot commented Apr 26, 2024

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Apr 26, 2024
@getsantry getsantry bot closed this May 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants