feat:實作 API 效能優化 — Redis 快取、分頁、DB 索引
- 引入 Redis(predis)快取層:Admin Stats(5分鐘)、課程列表(3分鐘,tag-based 失效)、評價分布(10分鐘) - ReviewController::publicList 改為 paginate + eager load votes,消除 N+1 - AdminReviewController::index 加入分頁(預設 20,最大 100) - 新增 notifications / diving_offers 效能索引 migration - 新增 docker-compose.override.yml 本機開發 port mapping 機制(不進 git) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\API;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\DivingOffer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AdminStatsController extends Controller
|
||||
{
|
||||
@@ -14,13 +15,12 @@ class AdminStatsController extends Controller
|
||||
return response()->json(['status' => false, 'message' => '無權限存取'], 403);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => [
|
||||
'total_members' => User::where('role', 'member')->count(),
|
||||
'total_providers' => User::where('role', 'provider')->count(),
|
||||
'total_offers' => DivingOffer::count(),
|
||||
],
|
||||
$stats = Cache::remember('admin_stats', 300, fn() => [
|
||||
'total_members' => User::where('role', 'member')->count(),
|
||||
'total_providers' => User::where('role', 'provider')->count(),
|
||||
'total_offers' => DivingOffer::count(),
|
||||
]);
|
||||
|
||||
return response()->json(['status' => true, 'data' => $stats]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user