[REFACTOR] 優化資料庫查詢效能:在多個 Service 與 Controller 中加入 select 欄位限制,並新增租戶資料表索引 Migration。

This commit is contained in:
2026-03-09 14:59:37 +08:00
parent 89291918fd
commit a987f4345e
13 changed files with 143 additions and 24 deletions

View File

@@ -151,7 +151,7 @@ class RoleController extends Controller
*/
private function getGroupedPermissions()
{
$allPermissions = Permission::orderBy('name')->get();
$allPermissions = Permission::select('id', 'name', 'guard_name')->orderBy('name')->get();
$grouped = [];
foreach ($allPermissions as $permission) {

View File

@@ -16,7 +16,7 @@ class CoreService implements CoreServiceInterface
*/
public function getUsersByIds(array $ids): Collection
{
return User::whereIn('id', $ids)->get();
return User::select('id', 'name')->whereIn('id', $ids)->get();
}
/**
@@ -37,7 +37,7 @@ class CoreService implements CoreServiceInterface
*/
public function getAllUsers(): Collection
{
return User::all();
return User::select('id', 'name')->get();
}
public function ensureSystemUserExists()