fix: 修复滑完后卡在等待状态的问题

- findBestMatch 不再返回 null,无人 like 时按评分兜底推荐
- 移除即时匹配的 users.length > 1 限制,支持单人房间
This commit is contained in:
2026-02-24 17:30:59 +08:00
parent e2c3b869eb
commit a72f7ed884
2 changed files with 8 additions and 15 deletions
+7 -11
View File
@@ -30,13 +30,11 @@ export async function GET(
if (match) {
matchType = "unanimous";
matchLikes = data.users.length;
} else if (allFinished) {
} else if (allFinished && data.restaurants.length > 0) {
const best = findBestMatch(data.likes, data.restaurants);
if (best) {
match = best.id;
matchType = "best";
matchLikes = best.likes;
}
match = best.id;
matchType = "best";
matchLikes = best.likes;
}
return NextResponse.json({
@@ -59,14 +57,13 @@ export async function GET(
function findBestMatch(
likes: Record<string, string[]>,
restaurants: { id: string; rating: number }[],
): { id: string; likes: number } | null {
let bestId: string | null = null;
): { id: string; likes: number } {
let bestId = restaurants[0].id;
let bestLikes = 0;
let bestRating = 0;
let bestRating = restaurants[0].rating;
for (const r of restaurants) {
const count = likes[r.id]?.length ?? 0;
if (count === 0) continue;
if (
count > bestLikes ||
@@ -78,6 +75,5 @@ function findBestMatch(
}
}
if (!bestId) return null;
return { id: bestId, likes: bestLikes };
}
+1 -4
View File
@@ -28,10 +28,7 @@ export async function POST(
data.likes[rid].push(userId);
}
if (
data.users.length > 1 &&
data.likes[rid].length === data.users.length
) {
if (data.likes[rid].length === data.users.length) {
data.match = rid;
}
}