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

Integrating React Query to improve performance #2822

Merged
merged 24 commits into from Apr 23, 2024
Merged

Conversation

anshg1214
Copy link
Member

This PR adds React-Query to the loader to enable caching of the results.

@anshg1214 anshg1214 changed the title React query Integrating React Query to improve performance Mar 22, 2024
Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

Good job on working out how to do this!
I'm still seeing an issue with initial data being undefined, see below

frontend/js/src/routes/EntityPages.tsx Outdated Show resolved Hide resolved
frontend/js/src/release/Release.tsx Outdated Show resolved Hide resolved
frontend/js/src/artist/ArtistPage.tsx Outdated Show resolved Hide resolved
queries: {
refetchOnWindowFocus: false,
retry: 1,
staleTime: 1000 * 60 * 5,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds reasonable for here.

For pages like the user dashboard, as soon as we have a timestamp (i.e not on the first page of my listens) we can cache the results for a loooong time since the API results should be the same (barring deleted listens, the deletion process is run once an hour I think?)

@anshg1214 anshg1214 requested a review from MonkeyDo April 1, 2024 20:38
frontend/js/src/user/Dashboard.tsx Show resolved Hide resolved
frontend/js/src/user/Dashboard.tsx Outdated Show resolved Hide resolved
frontend/js/src/user/Dashboard.tsx Outdated Show resolved Hide resolved
frontend/js/src/user/Dashboard.tsx Outdated Show resolved Hide resolved
setListens(initialListens || []);
}, [initialListens]);

const createWebsocketsConnection = React.useCallback((): void => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess eventually we're going to want to extract the websocket connection management to a higher level and have it available via a react context.

However you know my refrain by now :) : let's keep it for a separate PR to avoid overcharging this one

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, that the plan for the next PR, since socket is being used by multiple components

Copy link
Contributor

@MonkeyDo MonkeyDo Apr 9, 2024

Choose a reason for hiding this comment

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

I mentioned this in our video chat, I'm not so sure anymore that we want to do that 😅
Basically, we use websocket connections for two pages only at the moment: the user listens page and the playlist page,
In both cases, once the user navigates away to another tab or page, there's really no reason to keep using resources by keeping the websocket connection open.

I can see a future in which we get website notifications show in the UI, or a Playing Now conmponent visible across the website, or something like that, but it might be best to wait until we have that feature in mind.

We also talked with lucifer a little while back about possibly replacing websockets with server-sent events, so maybe we should also revisit that idea before refactoring WS on the frontend.

frontend/js/src/user/Dashboard.tsx Show resolved Hide resolved
websocketsUrl,
]);

const updateFollowingList = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self, refactor this into a FollowingList component that will take in a user prop, and take care of holding state for the list of followers as well as UI update code that we have here,

frontend/js/src/user/Dashboard.tsx Outdated Show resolved Hide resolved
frontend/js/src/utils/Loader.ts Outdated Show resolved Hide resolved
frontend/js/src/utils/utils.tsx Show resolved Hide resolved
Base automatically changed from spa-entity-pages to single-page-app April 12, 2024 16:03
@anshg1214 anshg1214 requested a review from MonkeyDo April 12, 2024 17:33
Replacing { data as MyTypes} force typing with the recommended useQuery<MyTypes>(...)
 + remove unused removeListenFromListenList function
This effect should be run exactly once on startup
Copy link
Contributor

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

Let's goooooo !

I took the liberty to fix up the typescript types of the useQuery calls, as the data can be undefined we were potentially creating error scenarios where forcing the type hid the underlying issue.

Also updated the branch with latest single-page-app so that it's ready to merge (there was one conflict)

@MonkeyDo MonkeyDo merged commit 8b8da7f into single-page-app Apr 23, 2024
3 of 4 checks passed
@MonkeyDo MonkeyDo deleted the react-query branch April 23, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants