Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

useFrecencySorting ignores how long ago an item was visited when sorting

クローズ 初心者向け
#84 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

  • #85 @auraseb による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

比較関数と src/useFrecencySorting.ts の getNewFrecency から始め、訪問時に保存スコアがどのように更新されるかと、項目がどのように順位付けされるかを比較してください。最後の訪問が60日前の項目と、今日2回訪問した項目を比較して、最小再現例を確認してください。並べ替えが経過時間を考慮し、このケースで新しい項目が先頭になれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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:

  1. 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.
  2. 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.

主要言語
TypeScript
スター
85
フォーク
19
平均マージ
8分
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

raycast/utils のほかの issue

raycast/utils の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。