useFrecencySorting ignores how long ago an item was visited when sorting
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- developer-experience
Research direction
Start with the comparator and getNewFrecency in src/useFrecencySorting.ts; compare how the stored score is updated on visits with how items are ranked. Check the minimal repro by comparing an item last visited 60 days ago with one visited twice today. Done when sorting accounts for elapsed time and the fresh item ranks first in that case.
Written by the indexing model from the issue text.
Description
What happens
useFrecencySorting stores, for each item, a score and the time of the last visit. When the list is sorted, the stored scores are compared directly:
if (frecencyA && frecencyB) {
return frecencyB.frecency - frecencyA.frecency;
}
The stored score is only decayed when the same item is visited again (in getNewFrecency). At sort time, a score from a year ago and a score from today are treated as if they were taken at the same moment. As a result:
- Two items visited once each always tie at 100, no matter whether the visit was today or a year ago, so the list falls back to the original order.
- An item visited 4 times two months ago (stored score 400) stays above an item visited twice today (stored score 200) forever. With the 10 day half life the old score is worth about 6 today.
Once an item has accumulated a high score it can never be overtaken by recent usage of other items unless it is reset.
What should happen
The docs say "The more often an item is visited, and the more recently an item is visited, the higher it will rank." Recent visits should outrank old ones of the same or similar weight, as in the Firefox algorithm the hook is based on.
Minimal repro
// visit "stale" 4 times, then wait 60 days, then visit "fresh" twice
const { data, visitItem } = useFrecencySorting([{ id: "stale" }, { id: "fresh" }]);
// data is [stale, fresh]; expected [fresh, stale]
Root cause
The comparator in src/useFrecencySorting.ts uses frecency without applying the decay for the time elapsed since lastVisited. Decaying both scores to the same now before comparing fixes it. getNewFrecency already has the decay formula, so it can be shared.
- Dominant language
- TypeScript
- Stars
- 85
- Forks
- 18
- Avg merge
- 12m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from raycast/utils
-
Feature_Request: OAuthService refreshToken support extra queryMay be free again @thomaslombart claimed this 888 days ago, and no pull request is open. Open
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Koenkk/zigbee-herdsman-converters#13540 ·
Maintainers usually reply within 1 day
-
check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
iptv-org/iptv#55821 · 1 comment ·
Maintainers usually reply within 1 day
-
area/busola/ux
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
kyma-project/busola#5442 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vercel-labs/wterm#246 ·
Maintainers usually reply within 1 day