Add Shorten view count numbers using K, M, B suffixes - #9721
Conversation
Head branch was pushed to by a user without write access
|
This is a little bit beyond the initial issue, but I remarked that comment likes have the same issue, they will be displayed as "202000" or "2200" instead of "202k" and "2k2" |
I think this would be within scope and I'm happy to add it. If we're doing this, then I feel we should make it consistent wherever the number is rounded. I've also found it in these places, let me know if I missed anywhere:
Then as you suggested, it would make sense to have this as function with an argument for number of zeroes to check for. We would also have to decide at which point it should use short notation. For now it only catches a view count >= 10,000, while technically view counts in the thousands are also rounded. If we lower this, the chances of a non-rounded, but matching number will be caught. For example in search results, one video may by chance have 1,234,500 views and be affected, while all others around it would not. |
|
There is something I'm missing, we have view count that are displayed with the same component but sometimes in places where YouTube shorten them and sometimes not, and there is no way to determine that? I can't really search myself because I don't have access to a computer, but if the previous answer is yes, will it be possible to determine the places where YouTube shorten the counts, and pass a bool to the component to indicate that "this element contains only shorten count" ? For the other places where shorten count appear, I would agree to do the same, but I would prefer that a code owner answer. |
|
Okay so clearly someone else needs to step in again here and steer the two of you back into the correct direction. Firstly @Shadorc I already said that saving extra data just for this was a bad idea in the linked issue, not only is it unnecessary because you can just do some math on the number to figure it out but would also mean that we would only display numbers that were saved after this pull request in compact notation. So please lets not go back to that. Secondly @ozrendev most of that code should not be in the template, it makes it harder to read and also means it runs more often than necessary. Video gets marked as watched, that formatting code gets run again, video gets added or removed from a playlist, you guessed it it runs again, etc. This is a prime candidate for a computed ref. As for the actual implementation of detecting which numbers should be compacted, which you are both stuck on, maybe I am missing something but, it should be as simple as this pseudo code: |
|
The possible issue with that was if we have for example three view counts that are not shorten 1234, 1200, 4567, the second one would be shorten. There is only 1% chance that it happens per video, si this could be considered minor enough to be ignored. |
|
I've made the above changes now. This logic works with way the view count is returned, I just used
I think with this approach it just may have to happen. When the view count gets higher, it becomes such a rare chance anyway. |
Pull Request Type
Related issue
closes #9522
Description
Adds a helper function to detect if a number (view count) has been rounded
Calls this function when displaying view counts and shortens the number as per
Intl.NumberFormatformatting if trueTesting
Search for any video, see that returned search results view count is not shortened as they contain exact numbers
Watch any video, see recommended videos rounded view count have now been shortened