From 313c1cf035b8b8d86cdd00814a80a38a723e5ed8 Mon Sep 17 00:00:00 2001 From: Tajim Date: Tue, 22 Sep 2026 22:22:50 +0600 Subject: [PATCH 1/4] feat(peers): prioritize mutual connections in PYMK algorithm --- app/Http/Controllers/PeerController.php | 13 +++++++++++++ tests/Feature/PeerTest.php | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/Http/Controllers/PeerController.php b/app/Http/Controllers/PeerController.php index 41d9a4d3..ebcebec3 100644 --- a/app/Http/Controllers/PeerController.php +++ b/app/Http/Controllers/PeerController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\User; +use App\Models\UserAppreciation; use Illuminate\Http\Request; use Inertia\Inertia; use Inertia\Response; @@ -57,6 +58,18 @@ public function index(Request $request): Response if ($sort === 'appreciated') { $query->orderByDesc('appreciations_received_count')->latest('users.id'); } else { + // 1. Primary: Mutual connections (friends of friends) for authenticated users + if ($currentUser) { + $query->selectSub( + UserAppreciation::query() + ->selectRaw('count(*)') + ->whereIn('appreciator_id', $currentUser->appreciationsGiven()->select('user_id')) + ->whereColumn('user_appreciations.user_id', 'users.id'), + 'mutual_count' + )->orderByDesc('mutual_count'); + } + + // 2. Fallback: Institution / location matching $targetLocation = $currentUser?->institution ? trim($currentUser->institution) : ''; // For guests or users without institution, infer location from Cloudflare headers diff --git a/tests/Feature/PeerTest.php b/tests/Feature/PeerTest.php index 5007b678..a6f0fb36 100644 --- a/tests/Feature/PeerTest.php +++ b/tests/Feature/PeerTest.php @@ -167,3 +167,24 @@ ->where('peers.data.0.is_appreciated', true) ); }); + +test('peers in You May Know prioritizes mutual connections', function () { + $viewer = User::factory()->create(['name' => 'Current Viewer']); + $friend = User::factory()->create(['name' => 'Direct Friend']); + $mutualPeer = User::factory()->create(['name' => 'Mutual Friend Candidate']); + $randomPeer = User::factory()->create(['name' => 'Random Candidate']); + + // Viewer appreciates Friend + $friend->appreciators()->attach($viewer->id); + + // Friend appreciates Mutual Peer + $mutualPeer->appreciators()->attach($friend->id); + + $response = $this->actingAs($viewer)->get(route('peers.index', ['sort' => 'relevant'])); + + $response->assertOk() + ->assertInertia(fn ($page) => $page + ->component('Peers/Index') + ->where('peers.data.0.name', 'Mutual Friend Candidate') + ); +}); From ea6593914d9cf467e47eda87dc418313457ea80f Mon Sep 17 00:00:00 2001 From: Tajim Date: Tue, 22 Sep 2026 22:24:27 +0600 Subject: [PATCH 2/4] feat(peers): switch final PYMK fallback to random order --- app/Http/Controllers/PeerController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/PeerController.php b/app/Http/Controllers/PeerController.php index ebcebec3..9a66f319 100644 --- a/app/Http/Controllers/PeerController.php +++ b/app/Http/Controllers/PeerController.php @@ -99,7 +99,7 @@ public function index(Request $request): Response } } - $query->latest('users.id'); + $query->inRandomOrder(); } $peers = $query->simplePaginate(20)->withQueryString(); From 14122e210a69b1df3bd26f4c7924ae4da570cf17 Mon Sep 17 00:00:00 2001 From: Tajim Date: Tue, 22 Sep 2026 22:25:27 +0600 Subject: [PATCH 3/4] Revert "feat(peers): switch final PYMK fallback to random order" This reverts commit ea6593914d9cf467e47eda87dc418313457ea80f. --- app/Http/Controllers/PeerController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/PeerController.php b/app/Http/Controllers/PeerController.php index 9a66f319..ebcebec3 100644 --- a/app/Http/Controllers/PeerController.php +++ b/app/Http/Controllers/PeerController.php @@ -99,7 +99,7 @@ public function index(Request $request): Response } } - $query->inRandomOrder(); + $query->latest('users.id'); } $peers = $query->simplePaginate(20)->withQueryString(); From 221b82ab5f7e87c666e55608bf60f9daca6ed1a1 Mon Sep 17 00:00:00 2001 From: Tajim Date: Tue, 22 Sep 2026 22:28:10 +0600 Subject: [PATCH 4/4] feat(navigation): show login button for guest users in mobile top bar --- .../js/components/navigation/Navigation.tsx | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/resources/js/components/navigation/Navigation.tsx b/resources/js/components/navigation/Navigation.tsx index b4968ba7..60ac61e6 100644 --- a/resources/js/components/navigation/Navigation.tsx +++ b/resources/js/components/navigation/Navigation.tsx @@ -1024,18 +1024,31 @@ export const SiteDrawer = defineComponent({
- {isHome.value && ( + {user.value ? ( + <> + {isHome.value && ( + + + Find + + )} + + + ) : !currentUrl.value.startsWith('/login') ? ( - - Find + + Login - )} - + ) : null}