Optimize queries: fix N+1, SELECT *, and missing eager loading

N+1 fixes:
- Add withCount('furniture') to rare categories sidebar (prevents N queries)
- Add tags and user.permission eager load in ArticleController
- Add rooms and photos.user eager load in ProfileController
- Add user eager load in MediaApiController (API was returning null user data)

SELECT * fixes:
- Replace WebsitePermission::all()->pluck() with direct pluck()
- Replace WebsiteHousekeepingPermission::all()->pluck() with direct pluck()
- Add select(['id', 'public_name']) to ItemBase query in furniItems()
- Add select(['id', 'name']) to help categories query
- Add select(['id', 'name', 'code']) to languages query

Memory/performance:
- Replace full collection load with aggregate queries in getRareStatistics()
- Add limit(50) to open tickets query in TicketController
This commit is contained in:
root
2026-06-29 18:50:32 +02:00
parent f29ba72591
commit 1acd96b78a
9 changed files with 18 additions and 14 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ class SettingsService
return collect();
}
return WebsiteLanguage::all();
return WebsiteLanguage::get(['id', 'name', 'code']);
} catch (Throwable) {
return collect();
}