Skip to content

Commit b9beffb

Browse files
Merge branch 'main' into filament-admin
2 parents 1e4945c + 97e11e4 commit b9beffb

30 files changed

+322
-373
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
coverage: none
3333

3434
- name: Setup Node
35-
uses: actions/setup-node@v4
35+
uses: actions/setup-node@v5
3636
with:
3737
node-version: '22.x'
3838

app/Http/Controllers/Articles/ArticlesController.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,27 @@ public function index(Request $request)
4545
->latest('approved_at')
4646
->{$filter}();
4747

48-
$tags = Tag::whereHas('articles', function ($query) {
49-
$query->published();
50-
})->orderBy('name')->get();
48+
$tags = Tag::whereHas('articles', fn ($query) => $query->published())
49+
->orderBy('name')
50+
->get();
5151

5252
if ($activeTag = Tag::where('slug', $request->tag)->first()) {
5353
$articles->forTag($activeTag->slug());
5454
}
5555

56-
$moderators = Cache::remember('moderators', now()->addMinutes(30), function () {
57-
return User::moderators()->get();
58-
});
59-
6056
$canonical = canonical('articles', ['filter' => $filter, 'tag' => $activeTag?->slug()]);
61-
$topAuthors = Cache::remember('topAuthors', now()->addMinutes(30), function () {
62-
return User::mostSubmissionsInLastDays(365)->take(5)->get();
63-
});
57+
$topAuthors = Cache::remember(
58+
'topAuthors',
59+
now()->addMinutes(30),
60+
fn () => User::mostSubmissionsInLastDays(365)->take(5)->get()
61+
);
6462

6563
return view('articles.overview', [
6664
'pinnedArticles' => $pinnedArticles,
6765
'articles' => $articles->paginate(10),
6866
'tags' => $tags,
6967
'activeTag' => $activeTag,
7068
'filter' => $filter,
71-
'moderators' => $moderators,
7269
'canonical' => $canonical,
7370
'topAuthors' => $topAuthors,
7471
]);
@@ -155,7 +152,7 @@ public function update(ArticleRequest $request, Article $article)
155152

156153
$article = $article->fresh();
157154

158-
if ($wasNotPreviouslySubmitted && $request->shouldBeSubmitted()) {
155+
if ($wasNotPreviouslySubmitted && $request->shouldBeSubmitted() && $article->isNotApproved()) {
159156
$this->success('Thank you for submitting, unfortunately we can\'t accept every submission. You\'ll only hear back from us when we accept your article.');
160157
} else {
161158
$this->success('Article successfully updated!');

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Controllers\Controller;
66
use App\Http\Requests\RegisterRequest;
77
use App\Jobs\RegisterUser;
8+
use App\Jobs\UpdateUserIdenticonStatus;
89
use App\Models\User;
910
use App\Providers\AppServiceProvider;
1011
use Illuminate\Auth\Events\Registered;
@@ -71,6 +72,10 @@ protected function create(RegisterRequest $request): User
7172
{
7273
$this->dispatchSync(RegisterUser::fromRequest($request));
7374

74-
return User::findByEmailAddress($request->emailAddress());
75+
$user = User::findByEmailAddress($request->emailAddress());
76+
77+
$this->dispatch(new UpdateUserIdenticonStatus($user));
78+
79+
return $user;
7580
}
7681
}

app/Http/Controllers/Forum/TagsController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\Tag;
88
use App\Models\Thread;
99
use App\Models\User;
10+
use Illuminate\Support\Facades\Cache;
1011
use Illuminate\View\View;
1112

1213
class TagsController extends Controller
@@ -35,8 +36,12 @@ public function show(Tag $tag): View
3536
}
3637

3738
$tags = Tag::orderBy('name')->get();
38-
$topMembers = User::mostSolutionsInLastDays(365)->take(5)->get();
39-
$moderators = User::moderators()->get();
39+
$topMembers = Cache::remember('topMembers', now()->addHour(), function () {
40+
return User::mostSolutionsInLastDays(365)->take(5)->get();
41+
});
42+
$moderators = Cache::remember('moderators', now()->addDay(), function () {
43+
return User::moderators()->get();
44+
});
4045
$canonical = canonical('forum.tag', [$tag->name, 'filter' => $filter]);
4146

4247
return view('forum.overview', compact('threads', 'filter', 'tags', 'topMembers', 'moderators', 'canonical') + ['activeTag' => $tag]);

app/Http/Controllers/Forum/ThreadsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function overview()
6161
}
6262

6363
$tags = Tag::orderBy('name')->get();
64-
$topMembers = Cache::remember('topMembers', now()->addMinutes(30), function () {
64+
$topMembers = Cache::remember('topMembers', now()->addHour(), function () {
6565
return User::mostSolutionsInLastDays(365)->take(5)->get();
6666
});
67-
$moderators = Cache::remember('moderators', now()->addMinutes(30), function () {
67+
$moderators = Cache::remember('moderators', now()->addDay(), function () {
6868
return User::moderators()->get();
6969
});
7070
$canonical = canonical('forum', ['filter' => $filter]);
@@ -74,7 +74,7 @@ public function overview()
7474

7575
public function show(Thread $thread)
7676
{
77-
$moderators = Cache::remember('moderators', now()->addMinutes(30), function () {
77+
$moderators = Cache::remember('moderators', now()->addDay(), function () {
7878
return User::moderators()->get();
7979
});
8080

app/Http/Controllers/HomeController.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,34 @@ class HomeController extends Controller
1313
{
1414
public function show()
1515
{
16-
$communityMembers = Cache::remember('communityMembers', now()->addMinutes(5), function () {
17-
return User::withCounts()
18-
->hasActivity()
19-
->notBanned()
20-
->inRandomOrder()
21-
->take(100)
22-
->get()
23-
->chunk(20);
24-
});
16+
$communityMembers = Cache::remember(
17+
'communityMembers',
18+
now()->addMinutes(5),
19+
fn () => User::notBanned()->withAvatar()->inRandomOrder()->take(100)->get()->chunk(20)
20+
);
2521

26-
$totalUsers = Cache::remember('totalUsers', now()->addDay(), function () {
27-
return number_format(User::notBanned()->count());
28-
});
22+
$totalUsers = Cache::remember('totalUsers', now()->addDay(), fn () => number_format(User::notBanned()->count()));
2923

30-
$totalThreads = Cache::remember('totalThreads', now()->addDay(), function () {
31-
return number_format(Thread::count());
32-
});
24+
$totalThreads = Cache::remember('totalThreads', now()->addDay(), fn () => number_format(Thread::count()));
3325

34-
$totalReplies = Cache::remember('totalReplies', now()->addDay(), function () {
35-
return number_format(Reply::count());
36-
});
26+
$totalReplies = Cache::remember('totalReplies', now()->addDay(), fn () => number_format(Reply::count()));
3727

38-
$latestThreads = Cache::remember('latestThreads', now()->addHour(), function () {
39-
return Thread::whereNull('solution_reply_id')
28+
$latestThreads = Cache::remember(
29+
'latestThreads',
30+
now()->addHour(),
31+
fn () => Thread::whereNull('solution_reply_id')
4032
->whereBetween('threads.created_at', [now()->subMonth(), now()])
4133
->unlocked()
4234
->inRandomOrder()
4335
->limit(3)
44-
->get();
45-
});
36+
->get()
37+
);
4638

47-
$latestArticles = Cache::remember('latestArticles', now()->addHour(), function () {
48-
return Article::published()
49-
->recent()
50-
->limit(4)
51-
->get();
52-
});
39+
$latestArticles = Cache::remember(
40+
'latestArticles',
41+
now()->addHour(),
42+
fn () => Article::published()->recent()->limit(4)->get()
43+
);
5344

5445
return view('home', [
5546
'communityMembers' => $communityMembers,

app/Jobs/CreateArticle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public function handle(): void
6969

7070
private function canBeAutoApproved(): bool
7171
{
72-
return $this->shouldBeSubmitted && $this->author->canVerifiedAuthorPublishMoreArticleToday();
72+
return $this->shouldBeSubmitted && $this->author->canVerifiedAuthorPublishMoreArticlesToday();
7373
}
7474
}

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/UpdateArticle.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ public function handle(): void
5353

5454
if ($this->shouldUpdateSubmittedAt()) {
5555
$this->article->submitted_at = now();
56+
$this->article->approved_at = $this->canBeAutoApproved() ? now() : null;
5657
$this->article->save();
5758

58-
event(new ArticleWasSubmittedForApproval($this->article));
59+
if ($this->article->isAwaitingApproval()) {
60+
event(new ArticleWasSubmittedForApproval($this->article));
61+
}
5962
}
6063

6164
$this->article->syncTags($this->tags);
@@ -69,4 +72,9 @@ private function shouldUpdateSubmittedAt(): bool
6972
{
7073
return $this->shouldBeSubmitted && $this->article->isNotSubmitted();
7174
}
75+
76+
private function canBeAutoApproved(): bool
77+
{
78+
return $this->article->author()->canVerifiedAuthorPublishMoreArticlesToday();
79+
}
7280
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use App\Models\User;
6+
use App\Social\GithubUserApi;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Foundation\Bus\Dispatchable;
9+
use Illuminate\Foundation\Queue\Queueable;
10+
use Illuminate\Queue\InteractsWithQueue;
11+
use Illuminate\Queue\SerializesModels;
12+
13+
final class UpdateUserIdenticonStatus implements ShouldQueue
14+
{
15+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
16+
17+
public function __construct(protected User $user) {}
18+
19+
public function handle(GithubUserApi $github): void
20+
{
21+
$hasIdenticon = $github->hasIdenticon($this->user->githubId());
22+
23+
User::withoutSyncingToSearch(function () use ($hasIdenticon) {
24+
$this->user->update(['github_has_identicon' => $hasIdenticon]);
25+
});
26+
}
27+
}

0 commit comments

Comments
 (0)