Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ A developer who isn't here yet gets a page with their GitHub avatar, name, handl

Its page shows how many members are waiting to follow them: the members who followed them on GitHub when they were looked up, and the ones who clicked **Follow** on their page, which then reads **Waiting** and can be clicked again to stop waiting. Members also see the people they follow among them. When the developer signs up, everyone waiting follows them, and their notifications show those follows like any others. Who you wait to follow is in your data export, and goes when you delete your account. If you delete your account, your page doesn't come back as one of these, until you sign in again.

Sources: [looking handles up](app/Http/Controllers/ProfileLookupController.php), [lookup page](resources/js/pages/profile/lookup.tsx), [developer page](resources/js/pages/profile/unclaimed.tsx), [GitHub lookups](app/Actions/CreateGitHubProfile.php).
Its page also says how many commits mention them, like **12 commits mention them**, counting approved commits that mention `@handle` outside code, refreshed within the hour. The commits themselves aren't shown or linked, since they can't answer what's said about them.

Sources: [looking handles up](app/Http/Controllers/ProfileLookupController.php), [lookup page](resources/js/pages/profile/lookup.tsx), [developer page](resources/js/pages/profile/unclaimed.tsx), [GitHub lookups](app/Actions/CreateGitHubProfile.php), [mention count](app/Queries/UnclaimedProfileMentionCountQuery.php).

### Going live

Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/UnclaimedProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Http\Requests\ShowUnclaimedProfileRequest;
use App\Models\Profile;
use App\Models\User;
use App\Queries\UnclaimedProfileMentionCountQuery;
use App\Services\PageMetadata;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\RedirectResponse;
Expand All @@ -19,9 +20,9 @@
/**
* A developer looked up from GitHub who isn't on /dev/null yet has a page at their "@handle", with what GitHub
* shows of them but where they are, for anyone with the link, but kept out of search engines, with how many members
* wait to follow them. Signing in as them makes it theirs. Like users' pages, it moves for good to the handle's own case.
* wait to follow them, and how many commits mention them. Signing in as them makes it theirs. Like users' pages, it moves for good to the handle's own case.
*/
public function show(ShowUnclaimedProfileRequest $request, #[CurrentUser] ?User $currentUser, PageMetadata $metadata): RedirectResponse|Response
public function show(ShowUnclaimedProfileRequest $request, #[CurrentUser] ?User $currentUser, PageMetadata $metadata, UnclaimedProfileMentionCountQuery $mentions): RedirectResponse|Response
{
$profile = $request->profile();
assert($profile instanceof Profile);
Expand All @@ -37,6 +38,8 @@ public function show(ShowUnclaimedProfileRequest $request, #[CurrentUser] ?User

return Inertia::render('profile/unclaimed', [
'profile' => $profile->only(['id', 'handle', 'name', 'avatar_url', 'bio']),
// Counting reads through the commits, so the page doesn't wait for it...
'mentionCount' => Inertia::defer(fn (): int => $mentions->get($profile)),
'waitingCount' => fn (): int => $waiting->clone()->count(),
'isWaiting' => fn (): bool => $currentUser instanceof User && $waiting->clone()->where('user_id', $currentUser->id)->exists(),
// Who follows whom is for members, so only they see who is waiting, among the people they follow...
Expand Down
41 changes: 41 additions & 0 deletions app/Queries/UnclaimedProfileMentionCountQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace App\Queries;

use App\Models\Commit;
use App\Models\Profile;
use App\Services\Mentions;
use Illuminate\Support\Facades\Cache;

final readonly class UnclaimedProfileMentionCountQuery
{
/**
* Mentions only go up a little at a time, and counting them reads through the commits, so the count is kept an hour.
*/
private const int CACHE_SECONDS = 3600;

public function __construct(private Mentions $mentions)
{
//
}

/**
* How many approved commits mention the developer as "@handle", by the same rules that link mentions, so one in
* code doesn't count. Just a number on their page: what others say about someone who isn't here stays off it.
* A handle has only letters, digits and "-", so it can't widen the pattern.
*/
public function get(Profile $profile): int
{
$handle = mb_strtolower($profile->handle);

return (int) Cache::remember("unclaimed-profile-mentions:{$handle}", self::CACHE_SECONDS, fn (): int => Commit::query()
->approved()
->where('body', 'ilike', "%@{$handle}%")
->select(['id', 'body'])
->lazyById(500)
->filter(fn (Commit $commit): bool => in_array($handle, $this->mentions->handles($commit->body), true))
->count());
}
}
23 changes: 21 additions & 2 deletions resources/js/pages/profile/unclaimed.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Head, router, usePage } from '@inertiajs/react';
import { Clock } from 'lucide-react';
import { AtSign, Clock } from 'lucide-react';
import { useState } from 'react';
import PendingFollowController from '@/actions/App/Http/Controllers/PendingFollowController';
import { show } from '@/actions/App/Http/Controllers/UserController';
Expand All @@ -25,15 +25,18 @@ type UnclaimedProfile = {

/**
* A developer looked up from GitHub who isn't on /dev/null yet. Signing in as them makes the page theirs. Where they
* are is left out, even when GitHub shows it: they never chose to share it here.
* are is left out, even when GitHub shows it: they never chose to share it here. So are the commits that mention them,
* which they can't answer: the page only counts them. Search wouldn't list them either, since it matches by meaning.
*/
export default function UnclaimedProfile({
profile,
mentionCount,
waitingCount,
isWaiting,
waitingYouFollow,
}: {
profile: UnclaimedProfile;
mentionCount?: number;
waitingCount: number;
isWaiting: boolean;
waitingYouFollow: Pick<User, 'id' | 'handle' | 'name' | 'avatar_url'>[];
Expand Down Expand Up @@ -114,6 +117,22 @@ export default function UnclaimedProfile({
github.com/{profile.handle}
</a>
</li>
{mentionCount !== undefined && mentionCount > 0 && (
<li className="flex items-center gap-1.5">
<AtSign className="size-4" />
<span data-test="mention-count">
<span
className="font-mono font-medium text-foreground tabular-nums"
title={exactCountTitle(mentionCount)}
>
{formatCount(mentionCount)}
</span>{' '}
{mentionCount === 1
? 'commit mentions them'
: 'commits mention them'}
</span>
</li>
)}
</ul>

{shownWaitingCount > 0 && (
Expand Down
15 changes: 15 additions & 0 deletions tests/Feature/Controllers/UnclaimedProfileControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Models\Commit;
use App\Models\Profile;
use App\Models\User;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -80,3 +81,17 @@
->where('isWaiting', true)
->where('waitingYouFollow', [$followed->only(['id', 'handle', 'name', 'avatar_url'])]));
});

it('counts the approved commits that mention them, but not mentions in code or of a longer handle', function (): void {
Profile::factory()->create(['handle' => 'octocat']);
Commit::factory()->create(['body' => 'Thanks @octocat!']);
Commit::factory()->create(['body' => 'Paired with @OctoCat and @hubot today']);
Commit::factory()->create(['body' => 'Found @octocat-fan in the wild']);
Commit::factory()->create(['body' => 'Use `@octocat` in your config']);
Commit::factory()->pending()->create(['body' => 'Waiting on @octocat']);

$this->get('/@octocat')
->assertInertia(fn ($page) => $page
->missing('mentionCount')
->loadDeferredProps(fn ($reload) => $reload->where('mentionCount', 2)));
});
Loading