Add monthly views chart

This commit is contained in:
2025-10-08 16:52:40 +02:00
parent 2880547f3e
commit fffa320c08
8 changed files with 144 additions and 30 deletions

View File

@@ -60,13 +60,6 @@ class CacheHelper
});
}
public static function getTotalMonthlyViews()
{
return Cache::remember("total_monthly_view_count", now()->addMinutes(60), function () {
return PopularMonthly::count();
});
}
public static function getPopularAllTime(bool $guest)
{
$guestString = $guest ? 'guest' : 'authed';

View File

@@ -2,16 +2,18 @@
namespace App\Http\Controllers\Api;
use App\Models\Downloads;
use App\Models\Hentai;
use App\Models\PopularMonthly;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use App\Http\Controllers\Controller;
class HentaiApiController extends Controller
{
public function index(Request $request)
/**
* Get a list of all hentai with it's episodes
*/
public function index()
{
// Cache for 10 minutes
$data = Cache::remember('api_hentai_list', now()->addMinutes(10), function () {
@@ -35,4 +37,20 @@ class HentaiApiController extends Controller
return response()->json($data);
}
/**
* Get monthly views by day for stats
*/
public function getMonthlyViews()
{
// Cache for 60 minutes
$data = Cache::remember('api_hentai_list', now()->addMinutes(60), function () {
return PopularMonthly::selectRaw('DATE(created_at) as date, COUNT(*) as count')
->groupBy('date')
->orderBy('date', 'asc')
->get();
});
return response()->json($data);
}
}

View File

@@ -87,7 +87,6 @@ class HomeController extends Controller
'viewCount' => CacheHelper::getTotalViewCount(),
'episodeCount' => CacheHelper::getTotalEpisodeCount(),
'hentaiCount' => CacheHelper::getTotalHentaiCount(),
'monthlyCount' => CacheHelper::getTotalMonthlyViews()
]);
}