-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try: use 'frecency' to sort items in the inserters #5342
Conversation
Use a heuristic that combines frequency and recency to sort the items that appear in the two inserters. The scoring function used is borrowed from z, an open source command line tool: https://github.com/rupa/z
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.
Code wise, this is looking good. I'll defer to @jasmussen and @karmatosed for the algorithm.
This seems good to me, though it's hard to test quickly as almost by definition we have to let this run for a while to test it. 👍 👍 |
Should we change the label? |
Yes good point, it's not recent anymore. Stumbling as to what though. Maybe we just don't have a label and say blocks, then library? |
It's too long, but for reference Slack uses "Frequently Used". |
What about just "Frequent" to make it shorter? |
Frequent 👍 (Or "Frecent"? 😉) |
"Popular" |
I've renamed the tab to Frequent 🙂 |
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 👍
insertUsage: { | ||
...prevState.insertUsage, | ||
[ id ]: { | ||
time: Date.now(), |
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.
Pedantry: Date.now
makes this reducer impure:
https://en.wikipedia.org/wiki/Functional_programming#Pure_functions
If a pure function is called with arguments that cause no side-effects, the result is constant with respect to that argument list ... i.e., if calling the pure function again with the same arguments returns the same result.
Violating a core principle of Redux:
Reducers are just pure functions that take the previous state and an action, and return the next state.
https://redux.js.org/introduction/three-principles#changes-are-made-with-pure-functions
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.
You're totally right. I'll move this to the action creator.
insertUsage: { | ||
'core-embed/twitter': { | ||
time: expect.any( Number ), |
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.
To the above point, we shouldn't have any need for expect.any
in this file, given that a reducer should be deterministic.
Out of curiosity, since Wondering about some of the selector arithmetic around |
Good point. |
Closes #5320.
Quick attempt at using frecency—a heuristic that combines frequency and recency—to sort the items that appear in both the main inserter and the quick inserter.
The scoring function I used is borrowed from z, an open source command line tool. We'll likely want to adjust the algorithm based on what feels right.
To test, insert a few different blocks and look at how that affects the Recent tab in the inserter. Recently inserted blocks should move to the top of the list, but they shouldn't displace very frequently used blocks.