-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
22 changed files
with
2,043 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Frontend; | ||
|
||
use App\Http\Controllers\Backend\StatisticController; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\View\View; | ||
use stdClass; | ||
|
||
class LandingPageController | ||
{ | ||
private const string CACHE_KEY_STATS = 'welcome.stats'; | ||
private const string CACHE_KEY_STATS_TTL = 'welcome.stats.revalidate'; | ||
private const string CACHE_KEY_STATS_CALCULATING = 'welcome.stats.calculating'; | ||
|
||
private function getStats(): stdClass { | ||
$stats = Cache::get(self::CACHE_KEY_STATS); | ||
$ttl = Cache::get(self::CACHE_KEY_STATS_TTL, 0); | ||
$calculating = Cache::get(self::CACHE_KEY_STATS_CALCULATING, false); | ||
|
||
// refresh stats if they are outdated. rand(0,10) to reduce risk of multiple processes starting calculation | ||
// $calculating to make sure, that there won't be multiple processes calculating the stats in the next 15 Minutes | ||
if ( | ||
($stats === null | ||
|| $ttl < now()->format('u')) | ||
&& !$calculating | ||
) { | ||
dispatch(function() { | ||
Cache::put(self::CACHE_KEY_STATS_CALCULATING, true, now()->addMinutes(15)); | ||
$stats = StatisticController::getGlobalCheckInStatsAllTime(); | ||
|
||
Cache::put(self::CACHE_KEY_STATS, $stats, now()->addDays(6)); | ||
Cache::put(self::CACHE_KEY_STATS_TTL, now()->addDays(5)->format('u')); | ||
})->afterResponse(); | ||
} | ||
|
||
// Fallback: Show bogus values if really nothing is set | ||
if ($stats === null) { | ||
$stats = new stdClass(); | ||
$stats->distance = 0; | ||
$stats->duration = 0; | ||
$stats->user_count = 0; | ||
} | ||
|
||
return $stats; | ||
} | ||
|
||
public function renderLandingPage(): View|RedirectResponse { | ||
if (Auth::check()) { | ||
return redirect()->route('dashboard'); | ||
} | ||
return view('welcome/welcome', ['stats' => $this->getStats()]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.