Skip to content

Commit 2419ca0

Browse files
committed
wip
1 parent c79b792 commit 2419ca0

File tree

12 files changed

+64
-19
lines changed

12 files changed

+64
-19
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Jobs\UpdateUserIdenticonStatus;
6+
use App\Models\User;
7+
use Illuminate\Console\Command;
8+
9+
class BackfillIdenticons extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'app:backfill-identicons';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Backfills the github_has_identicon column for users';
24+
25+
/**
26+
* Execute the console command.
27+
*/
28+
public function handle()
29+
{
30+
User::whereNotNull('github_id')
31+
->chunk(100, function ($users) {
32+
foreach ($users as $user) {
33+
UpdateUserIdenticonStatus::dispatch($user);
34+
}
35+
36+
sleep(2);
37+
});
38+
}
39+
}

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ public function register(RegisterRequest $request)
7171
protected function create(RegisterRequest $request): User
7272
{
7373
$this->dispatchSync(RegisterUser::fromRequest($request));
74+
7475
$user = User::findByEmailAddress($request->emailAddress());
76+
7577
$this->dispatch(new UpdateUserIdenticonStatus($user));
7678

77-
return User::findByEmailAddress($request->emailAddress());
79+
return $user;
7880
}
7981
}

app/Http/Controllers/HomeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function show()
1616
$communityMembers = Cache::remember(
1717
'communityMembers',
1818
now()->addMinutes(5),
19-
fn () => User::notBanned()->inRandomOrder()->take(100)->get()->chunk(20)
19+
fn () => User::notBanned()->withAvatar()->inRandomOrder()->take(100)->get()->chunk(20)
2020
);
2121

2222
$totalUsers = Cache::remember('totalUsers', now()->addDay(), fn () => number_format(User::notBanned()->count()));

app/Jobs/UnVerifyAuthor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Contracts\Queue\ShouldQueue;
77
use Illuminate\Foundation\Queue\Queueable;
88

9-
class UnVerifyAuthor implements ShouldQueue
9+
final class UnVerifyAuthor implements ShouldQueue
1010
{
1111
use Queueable;
1212

app/Jobs/UpdateUserIdenticonStatus.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ final class UpdateUserIdenticonStatus implements ShouldQueue
1414
{
1515
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
1616

17-
public function __construct(private User $user) {}
17+
public function __construct(protected User $user) {}
1818

1919
public function handle(GithubUserApi $github): void
2020
{
2121
$hasIdenticon = $github->hasIdenticon($this->user->githubId());
22-
$this->user->update(['has_identicon' => $hasIdenticon]);
22+
23+
$this->user->update(['github_has_identicon' => $hasIdenticon]);
2324
}
2425
}

app/Jobs/VerifyAuthor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Contracts\Queue\ShouldQueue;
77
use Illuminate\Foundation\Queue\Queueable;
88

9-
class VerifyAuthor implements ShouldQueue
9+
final class VerifyAuthor implements ShouldQueue
1010
{
1111
use Queueable;
1212

app/Models/User.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ final class User extends Authenticatable implements MustVerifyEmail
5858
'remember_token',
5959
'bio',
6060
'banned_reason',
61-
'has_identicon'
61+
'github_has_identicon'
6262
];
6363

6464
/**
@@ -76,6 +76,7 @@ protected function casts(): array
7676
return [
7777
'allowed_notifications' => 'array',
7878
'author_verified_at' => 'datetime',
79+
'github_has_identicon' => 'boolean',
7980
];
8081
}
8182

@@ -116,7 +117,7 @@ public function githubUsername(): string
116117

117118
public function hasIdenticon(): bool
118119
{
119-
return (bool) $this->has_identicon;
120+
return (bool) $this->github_has_identicon;
120121
}
121122

122123
public function twitter(): ?string
@@ -417,6 +418,11 @@ public function scopeModerators(Builder $query)
417418
]);
418419
}
419420

421+
public function scopeWithAvatar(Builder $query)
422+
{
423+
return $query->where('github_has_identicon', false);
424+
}
425+
420426
public function scopeNotBanned(Builder $query)
421427
{
422428
return $query->whereNull('banned_at');

app/Social/GithubUserApi.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Http\Client\ConnectionException;
66
use Illuminate\Support\Facades\Http;
77

8-
class GithubUserApi
8+
final class GithubUserApi
99
{
1010
public function find(int|string $id): ?GitHubUser
1111
{
@@ -17,22 +17,19 @@ public function find(int|string $id): ?GitHubUser
1717

1818
public function hasIdenticon(int|string $id): bool
1919
{
20-
$detectionSize = 40;
2120
$response = Http::retry(3, 300, fn ($exception) => $exception instanceof ConnectionException)
22-
->get("https://avatars.githubusercontent.com/u/{$id}?v=4&s={$detectionSize}");
21+
->get("https://avatars.githubusercontent.com/u/{$id}?v=4&s=40");
2322

2423
if ($response->failed()) {
2524
return true;
2625
}
2726

28-
$info = getimagesizefromstring($response->body());
29-
30-
if (!$info) {
27+
if (! $info = getimagesizefromstring($response->body())) {
3128
return true;
3229
}
3330

3431
[$width, $height] = $info;
3532

36-
return !($width === 420 && $height === 420);
33+
return ! ($width === 420 && $height === 420);
3734
}
3835
}

database/factories/UserFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function definition(): array
2323
'remember_token' => Str::random(10),
2424
'github_id' => $this->faker->unique()->numberBetween(10000, 99999),
2525
'github_username' => $this->faker->unique()->userName(),
26+
'github_has_identicon' => $this->faker->boolean(),
2627
'twitter' => $this->faker->unique()->userName(),
2728
'bluesky' => $this->faker->unique()->userName(),
2829
'website' => 'https://laravel.io',

database/migrations/2025_09_11_152525_add_has_identicon_to_users_table.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
public function up(): void
1010
{
1111
Schema::table('users', function (Blueprint $table) {
12-
$table->boolean('has_identicon')->after('bio')->default(false);
12+
$table->boolean('github_has_identicon')->after('github_username')->default(false);
1313
});
1414
}
15-
1615
};

0 commit comments

Comments
 (0)