-
Notifications
You must be signed in to change notification settings - Fork 2k
Remove unneeded selectors from stats/utils #21641
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
Conversation
It's only used in `PostTrends.shouldComponentUpdate` as an optimization attempt to reduce rerenders. The changes in #21507 achieve that goal better, though: by selector memoization and deep comparison of the `query` prop. The `shouldComponentUpdate` and the associated selector is no longer needed. This patch even solves a bug where the component wouldn't get rerendered when the `state.canScrollLeft` and `state.canScrollRight` flags changed, and the scrolling arrows on the "Posting Activity" chart wouldn't get the `is-active` CSS class.
| startDate; | ||
| const { streakData } = this.props; | ||
| // Compute maximum per-day post count from the streakData. It's used to scale the chart. | ||
| const maxPosts = reduce( streakData, ( max, count ) => ( count > max ? count : max ), 0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FFTI: could use _.max
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, converted to max( values( streakData ) ), as streakData is an object with shape { 'date1': count1, 'date2': count2, ... }.
| months = [], | ||
| startDate; | ||
| const { streakData } = this.props; | ||
| // Compute maximum per-day post count from the streakData. It's used to scale the chart. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice comment!
samouri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the testing instructions and everything worked as expected
timmyc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing out well for me, thanks for all the performance work you are doing in stats <3
|
Unsetting & setting Needs Review label to force re-run of canaries with failing desktop canary now fixed. |
It computes the maximum per-day post count from `streakData`. This calculation is better done in the `render` method of `PostTrends`. There it's performed only when the component is rerendered, and not each time some irrelevant action is performed. Another little drive-by fix is using month index as a `key`. That's completely sufficient, no need to format date string.
It's not used anywhere.
d1b5703 to
74788df
Compare
While working on #21507 and getting familiar with the Stats code, I realized that there are few selectors that can be removed. They are either not used, or can be replaced with something better:
Read the commit messages for details.
How to test:
Go to
/stats/insights/a8c.tvand play with the "Posting Activity" chart:When the width of the viewport is small, the chart should scroll and the scrolling arrows on the left and right site should switch between the "active" and "inactive" states. That verifies that the
PostTrendscomponent is rerendered when its state changes. That didn't work before, because itsshouldComponentUpdatewas broken and prevented the rerender.Also, verify that the "dots" in the chart use the full spectrum of colors. That's what the
getSiteStatsMaxPostsByDayselector used to help achieve and is now replaced by a computation directly in therendermethod.