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

fix: improve ChannelList performance by improving threshold calls and rerenders of Header #1919

Merged
merged 15 commits into from
Jan 23, 2023

Conversation

khushal87
Copy link
Member

🎯 Goal

This PR focuses on fixing the Header rerender issue in ChannelList if provided, and multiple queryChannels call when the threshold is reached and more data is loaded.

🛠 Implementation details

To fix the Header rerender the null check and channels.length check is removed as it wasn't really needed.
To fix the threshold API hits facebook/react-native#14015 (comment) and https://stackoverflow.com/a/60666252/10826415 was followed.

🎨 UI Changes

iOS
Before After
Android
Before After

🧪 Testing

☑️ Checklist

  • I have signed the Stream CLA (required)
  • PR targets the develop branch
  • Documentation is updated
  • New code is tested in main example apps, including all possible scenarios
    • SampleApp iOS and Android
    • Expo iOS and Android

const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
const [activeQueryType, setActiveQueryType] = useState<QueryType | null>(null);
const [hasNextPage, setHasNextPage] = useState<boolean>(false);
Copy link
Member

@santhoshvai santhoshvai Jan 20, 2023

Choose a reason for hiding this comment

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

also here, initally hasnextPage is true right as before? we dont know if its false.. but we can assume that there is always a nextPage and if not the api would return empty

Copy link
Member Author

@khushal87 khushal87 Jan 20, 2023

Choose a reason for hiding this comment

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

It makes more sense to be false initially. If there are more data, it will be true. It is almost the same thing just making it more readable

Copy link
Member

Choose a reason for hiding this comment

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

Usually these kind of things are set to true initially.. also explained by vishal in the call

Copy link
Member Author

Choose a reason for hiding this comment

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

But why can't it be false, this will never be true for the first fetch and can be true only if there are more data to load, right? Just asking to check if I am wrong here.

Eg: See loadingExtraData here - https://alexb72.medium.com/how-to-add-pagination-to-a-react-native-flatlist-ce2425d02f1a

Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't we receiving that info from our BE after the first fetch? I thought we had a "page_count" or such?

Copy link
Member Author

@khushal87 khushal87 Jan 20, 2023

Choose a reason for hiding this comment

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

Technically it makes more sense to keep it false so that no logic will load more/extra data initially no matter if there's any data or not; if there's more data after first call it will be true, and the query will be called automatically

Copy link
Member

Choose a reason for hiding this comment

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

if its false initially.. why does it query? I thought we query only if hasNextPage is true

Copy link
Member Author

@khushal87 khushal87 Jan 23, 2023

Choose a reason for hiding this comment

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

If you go through the code. queryType is reload for the first time, which means it should call queryChannels to get the first 30 sets of data, then if there's more data or equal data we set the hasNextPage to true and next call is done to get more data. Initially, if it's false it will be true after the first call if there's more data. What's the point in keeping it true since the beginning?

My point is regardless of what it is it will be true eventually if there's more data left to receive so why should we keep it true?

Copy link
Member Author

Choose a reason for hiding this comment

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

Check the useEffect for !enableOfflineSupport case and you will get what is happening.

Copy link
Contributor

Choose a reason for hiding this comment

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

@santhoshvai we set the hasNextPage only if after the first queryChannels call is made and when there is an extra page/data (we do it by calculating channelQueryResponse.length >= newOptions.limit).

Wit this PR we call queryChannels only when needed (hasNextPage is true) and use of resources has been limited

const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
const [activeQueryType, setActiveQueryType] = useState<QueryType | null>(null);
const [hasNextPage, setHasNextPage] = useState<boolean>(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't we receiving that info from our BE after the first fetch? I thought we had a "page_count" or such?

@vanGalilea
Copy link
Contributor

This PR get's my approval after we settle the discussion about the initial state of hasNextPage

@sonarcloud
Copy link

sonarcloud bot commented Jan 21, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

55.6% 55.6% Coverage
0.0% 0.0% Duplication

@vanGalilea vanGalilea merged commit 6ebabb6 into develop Jan 23, 2023
@vanGalilea vanGalilea deleted the khushal87/channel-list-performance branch January 23, 2023 09:19
@vanGalilea
Copy link
Contributor

After Beta release let's share with the relevant integrators!

@vanGalilea
Copy link
Contributor

@github-actions github-actions bot mentioned this pull request Jan 24, 2023
@vishalnarkhede
Copy link
Contributor

🎉 This PR is included in version 5.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

4 participants