Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,24 +743,13 @@ export const fetchActivity = cache(async function fetchActivity(

/**
* 効率的に Map から上位 K 件を抽出するヘルパー関数
* 配列の作成とソートを最小限に抑えることでパフォーマンスを向上させます
* 上位 K 件だけを返します。
*/
function getTopK(map: Map<string, number>, k: number = 10): { name: string; count: number }[] {
const top: { name: string; count: number }[] = [];
for (const [name, count] of map.entries()) {
if (top.length < k) {
top.push({ name, count });
top.sort((a, b) => b.count - a.count);
} else if (count > top[k - 1].count) {
let i = k - 2;
while (i >= 0 && top[i].count < count) {
top[i + 1] = top[i];
i--;
}
top[i + 1] = { name, count };
}
}
return top;
const limit = Math.max(0, k);
return Array.from(map, ([name, count]) => ({ name, count }))
.sort((a, b) => b.count - a.count)
.slice(0, limit);
}

/**
Expand Down
Loading