Skip to content

Commit

Permalink
Fix custom emoji admin dashboard bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Jan 21, 2022
1 parent 46d5f12 commit 1e00c43
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,15 @@ public function customEmojiHome(Request $request)
return redirect(route('admin.custom-emoji'));
}

$emojis = CustomEmoji::when($sort, function($query, $sort) use($request) {
$pg = config('database.default') == 'pgsql';

$emojis = CustomEmoji::when($sort, function($query, $sort) use($request, $pg) {
if($sort == 'all') {
return $query->groupBy('shortcode')->latest();
if($pg) {
return $query->latest();
} else {
return $query->groupBy('shortcode')->latest();
}
} else if($sort == 'local') {
return $query->latest()->where('domain', '=', config('pixelfed.domain.app'));
} else if($sort == 'remote') {
Expand All @@ -394,13 +400,20 @@ public function customEmojiHome(Request $request)
->simplePaginate(10)
->withQueryString();

$stats = Cache::remember('pf:admin:custom_emoji:stats', 43200, function() {
return [
$stats = Cache::remember('pf:admin:custom_emoji:stats', 43200, function() use($pg) {
$res = [
'total' => CustomEmoji::count(),
'active' => CustomEmoji::whereDisabled(false)->count(),
'remote' => CustomEmoji::where('domain', '!=', config('pixelfed.domain.app'))->count(),
'duplicate' => CustomEmoji::groupBy('shortcode')->havingRaw('count(*) > 1')->count()
];

if($pg) {
$res['duplicate'] = CustomEmoji::select('shortcode')->groupBy('shortcode')->havingRaw('count(*) > 1')->count();
} else {
$res['duplicate'] = CustomEmoji::groupBy('shortcode')->havingRaw('count(*) > 1')->count();
}

return $res;
});

return view('admin.custom-emoji.home', compact('emojis', 'sort', 'stats'));
Expand Down

0 comments on commit 1e00c43

Please sign in to comment.