fix: added og headers, lots of cleanup.

This commit is contained in:
2023-12-20 01:02:15 +00:00
parent 7772be7dc5
commit f7a27e7f62
17 changed files with 817 additions and 62 deletions

View File

@@ -18,8 +18,7 @@ class PageController extends Controller
$headerCounters = $this->getHeaderCounters();
$recentEpisodes = $this->mostRecentEpisodes();
$recentSubmissions = $this->mostRecentSubmissions();
$leaderboard = $this->leaderboardTwelveMonths();
$leaderboard = $this->leaderboardTwelveMonthsLanding();
return view('home.page', [
'user' => $user,
'pageTitle' => 'Home',
@@ -31,6 +30,31 @@ class PageController extends Controller
]);
}
public function leaderboards(Request $request)
{
$user = auth()->user();
return view('leaderboards.leaderboards', [
'user' => $user,
'leaderboardAllTime' => $this->leaderboardAllTime(),
'leaderboardPastTwelveMonths' => $this->leaderboardTwelveMonths(),
'leaderboardRollingSixMonths' => $this->leaderboardRollingSixMonths(),
'leaderboardRollingNinetyDays' => $this->leaderboardRollingNinetyDays(),
]);
}
public function support(Request $request)
{
return view('home.support.page', [
'user' => auth()->user(),
'pageTitle' => 'History and Support',
'headerCounters' => $this->getHeaderCounters(),
'recentEpisodes' => $this->mostRecentEpisodes(),
'recentSubmissions' => $this->mostRecentSubmissions(),
'leaderboard' => $this->leaderboardTwelveMonthsLanding(),
'preferredTheme' => $request->session()->get('preferred_theme') ?? 'dark',
]);
}
private function mostRecentSubmissions() {
$artworks = Cache::remember('latestSubmissions', 30, function() {
return Artwork::whereNotNull('approved_by')
@@ -52,7 +76,7 @@ class PageController extends Controller
->with('podcast')
->with('artwork')
->with('artwork.artist')
->orderBy('episode_date', 'desc')
->orderBy('episode_number', 'desc')
->limit(5)
->get();
});
@@ -101,6 +125,29 @@ class PageController extends Controller
private function leaderboardTwelveMonths() {
$leaderboard = cache()->remember('leaderboardTwelveMonths', 30, function() {
$endDate = now()->endOfDay()->subYear()->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->where('episodes.episode_date', '>=', $endDate)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(50)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function leaderboardTwelveMonthsLanding() {
$leaderboard = cache()->remember('leaderboardTwelveMonthsLanding', 30, function() {
$endDate = now()->endOfDay()->subYear()->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
@@ -122,6 +169,73 @@ class PageController extends Controller
return $leaderboard;
}
private function leaderboardAllTime() {
$leaderboard = cache()->remember('leaderboardAllTime', 30, function() {
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(100)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function leaderboardRollingSixMonths() {
$leaderboard = cache()->remember('leaderboardRollingSixMonth', 30, function() {
$endDate = now()->endOfDay()->subMonths(6)->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->where('episodes.episode_date', '>=', $endDate)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(50)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function leaderboardRollingNinetyDays() {
$leaderboard = cache()->remember('leaderboardNinetyDays', 30, function() {
$endDate = now()->endOfDay()->subDays(90)->format('Y-m-d');
$leaderboard = DB::table('episodes')
->join('artworks', 'artworks.id', '=', 'episodes.artwork_id')
->join('artists', 'artists.id', '=', 'artworks.artist_id')
->select([
DB::raw('artists.id as artistId'),
DB::raw('artists.name as artistName'),
DB::raw('count(artworks.id) as artworkCount')
])
->where('episodes.published', 1)
->where('episodes.episode_date', '>=', $endDate)
->groupBy('artistId')
->orderByDesc('artworkCount')
->limit(50)
->get();
$leaderboard = $this->addArtistModelToLeaderboard($leaderboard);
return $leaderboard;
});
return $leaderboard;
}
private function addArtistModelToLeaderboard($leaderboard) {
$artistIds = [];
foreach ($leaderboard as $lb) {