Skip to content

Commit 025a894

Browse files
committed
Improve Admin Instances page ✨
1 parent 5b863d6 commit 025a894

File tree

4 files changed

+294
-219
lines changed

4 files changed

+294
-219
lines changed

app/Console/Commands/UpdateInstanceStats.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function handle()
4747
$this->updateCommentCounts($domain);
4848
$this->updateReplyCounts($domain);
4949
$this->updateFollowerCounts($domain);
50+
$this->updateFollowingCounts($domain);
5051
$this->updateReportCounts($domain);
5152

5253
$this->info('Instance statistics updated successfully!');
@@ -258,7 +259,6 @@ protected function updateFollowerCounts($domain = null)
258259
{
259260
$this->info('Updating follower counts...');
260261

261-
// Count followers from remote instances (where the folower is from a remote instance)
262262
$query = "
263263
UPDATE instances i
264264
INNER JOIN (
@@ -285,6 +285,39 @@ protected function updateFollowerCounts($domain = null)
285285
$this->line('✓ Follower counts updated');
286286
}
287287

288+
/**
289+
* Update following counts for each instance
290+
*/
291+
protected function updateFollowingCounts($domain = null)
292+
{
293+
$this->info('Updating following counts...');
294+
295+
$query = "
296+
UPDATE instances i
297+
INNER JOIN (
298+
SELECT
299+
p.domain,
300+
COUNT(*) as following_count
301+
FROM followers f
302+
INNER JOIN profiles p ON f.following_id = p.id
303+
WHERE p.domain IS NOT NULL
304+
AND p.domain != ''
305+
AND f.profile_is_local = 1
306+
GROUP BY p.domain
307+
) f ON i.domain = f.domain
308+
SET i.following_count = f.following_count
309+
";
310+
311+
if ($domain) {
312+
$query .= ' WHERE i.domain = ?';
313+
DB::update($query, [$domain]);
314+
} else {
315+
DB::update($query);
316+
}
317+
318+
$this->line('✓ Following counts updated');
319+
}
320+
288321
/**
289322
* Update report counts for each instance
290323
*/

app/Http/Resources/AdminInstanceResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function toArray(Request $request)
4545
'reply_count' => $this->reply_count ?? 0,
4646
'comment_count' => $this->comment_count ?? 0,
4747
'follower_count' => $this->follower_count ?? 0,
48+
'following_count' => $this->following_count ?? 0,
4849
'report_count' => $this->report_count ?? 0,
4950
'federation_state' => (int) $this->federation_state,
5051
'admin_notes' => $this->admin_notes,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('instances', function (Blueprint $table) {
15+
$table->unsignedBigInteger('following_count')->nullable()->after('follower_count');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('instances', function (Blueprint $table) {
25+
$table->dropColumn('following_count');
26+
});
27+
}
28+
};

0 commit comments

Comments
 (0)