Skip to content

useFrecencySorting: decay scores to the current time before comparing - #85

Closed
sebxt wants to merge 1 commit into
raycast:mainfrom
sebxt:fix/frecency-ignores-recency-when-sorting
Closed

sebxt wants to merge 1 commit into
raycast:mainfrom
sebxt:fix/frecency-ignores-recency-when-sorting

Conversation

@sebxt

@sebxt sebxt commented Oct 19, 2026

Copy link
Copy Markdown

The sort in useFrecencySorting compared the stored scores directly. Those scores are only decayed when the same item is visited again, so an item that was used a lot a long time ago kept outranking items used recently, and single visits always tied regardless of when they happened. This contradicts the documented behaviour ("the more recently an item is visited, the higher it will rank").

This change moves the existing decay formula into getDecayedFrecency and uses it in both places: when a visit is recorded (unchanged behaviour) and in the comparator, where both scores are decayed to the same now before being compared. The stored format is unchanged, so existing cached data keeps working.

Tests: added test/useFrecencySorting.test.tsx covering an old visit vs a recent visit with the same score, many old visits vs a few recent ones (driven through visitItem), and frequency still winning when visits are equally recent. The first two fail on main and pass with this change. npm test and npm run lint pass.

Fixes #84

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
@mathieudutour

Copy link
Copy Markdown
Member

I fixed it directly, the direction of the PR was a bit off (we should be storing a timestamp in the first place)

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.

useFrecencySorting ignores how long ago an item was visited when sorting

2 participants