fix: admin queries and bootstrapping#132
Conversation
WalkthroughThe PR enhances caching for stats queries, refactors the application bootstrap sequence across service providers, removes the TenantsStatsOverview widget, improves UI field configuration with searchability, adds conditional debugbar support with configuration, and implements environment-aware database seeding logic. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (5)
app/Providers/Filament/GuestPanelProvider.php (3)
39-58: Large commented-out FOOTER hook could be removed or moved to config/docsThe entire
PanelsRenderHook::FOOTERblock is now commented out. If this footer isn’t coming back soon, consider deleting it (or moving the config/text into a markdown/docs file) to keep the provider lean and avoid stale UI fragments living in comments.
62-67: Github CTA change looks good; consider cleaning up the commented buttonAdding
href="https://github.com/he4rt"to the<x-he4rt::button>in the sidebar guest block is straightforward and keeps the CTA clear. If the “Entrar agora” button is no longer part of the UX, you might want to drop the HTML comment entirely instead of keeping it inline here.
74-79: Topbar Github CTA mirrors sidebar; optional DRY / cleanupSame as the sidebar: the Github link change is fine, and the commented-out “Entrar agora” button adds a bit of noise. If this pattern is finalized, you could either remove the commented code or extract a small shared Blade snippet for the Github button to avoid duplication between sidebar and topbar.
app-modules/tenant/src/Filament/Admin/Resources/Tenants/Schemas/TenantForm.php (1)
35-39: Confirm the impact oflimit(10)on searchable relationship optionsThe new
Select::make('owner_id')setup looks good and is idiomatic for Filament;native(false)+searchable()is a solid UX improvement.One subtle point: putting
->limit(10)insidemodifyQueryUsingwill cap all owner options to 10 rows, including when the user searches. Without an explicitorderBy, which 10 rows you get may also be arbitrary.If the intent is “only ever show 10” and that’s acceptable, this is fine. If you instead want “10 per page / per search, but full search coverage,” consider:
- Adding a deterministic sort, e.g.
orderBy('name'), and/or- Using Filament’s built‑in mechanisms for option limiting / pagination rather than a hard
limit()insidemodifyQueryUsing, per current Filament docs.app/Providers/AppServiceProvider.php (1)
53-56: Empty method - consider removing or implementing.
configureDates()is currently empty with only a commented-out example. If this is a placeholder for future implementation, consider adding a TODO comment or removing it to avoid dead code.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
composer.lockis excluded by!**/*.lock
📒 Files selected for processing (13)
app-modules/tenant/src/Filament/Admin/Resources/Tenants/Schemas/TenantForm.php(1 hunks)app-modules/tenant/src/Filament/Admin/Widgets/TenantsStatsOverview.php(0 hunks)app-modules/tenant/src/Plugins/AdminTenantPanelPlugin.php(0 hunks)app-modules/user/src/Filament/Admin/Resources/Users/UserResource.php(2 hunks)app-modules/user/src/Filament/Shared/Widgets/UsersStatsOverview.php(1 hunks)app-modules/user/src/Models/User.php(1 hunks)app-modules/user/src/Plugins/AdminUserPanelPlugin.php(2 hunks)app/Providers/AppServiceProvider.php(2 hunks)app/Providers/Filament/GuestPanelProvider.php(1 hunks)app/Providers/Tools/DebugbarServiceProvider.php(1 hunks)composer.json(2 hunks)config/debugbar.php(1 hunks)database/seeders/ThreeDotsSeeder.php(1 hunks)
💤 Files with no reviewable changes (2)
- app-modules/tenant/src/Plugins/AdminTenantPanelPlugin.php
- app-modules/tenant/src/Filament/Admin/Widgets/TenantsStatsOverview.php
🧰 Additional context used
🧬 Code graph analysis (4)
app-modules/user/src/Plugins/AdminUserPanelPlugin.php (1)
app-modules/user/src/Filament/Shared/Widgets/UsersStatsOverview.php (1)
UsersStatsOverview(13-51)
app-modules/user/src/Filament/Shared/Widgets/UsersStatsOverview.php (1)
app-modules/events/src/Filament/Shared/Widgets/ActiveEventsStats.php (1)
getStats(16-61)
app/Providers/AppServiceProvider.php (1)
app/Providers/Tools/DebugbarServiceProvider.php (2)
DebugbarServiceProvider(9-24)boot(11-18)
app-modules/user/src/Models/User.php (9)
app/Providers/Filament/GuestPanelProvider.php (1)
panel(28-125)app/Providers/Filament/EventPanelProvider.php (1)
panel(35-88)app/Providers/Filament/AdminPanelProvider.php (1)
panel(26-74)app/Providers/Filament/UserPanelProvider.php (1)
panel(28-68)app-modules/user/src/Plugins/AdminUserPanelPlugin.php (1)
getId(15-18)app-modules/tenant/src/Plugins/AdminTenantPanelPlugin.php (1)
getId(14-17)app-modules/events/src/AdminEventPanelPlugin.php (1)
getId(15-18)app-modules/season/src/AdminSeasonPanelPlugin.php (1)
getId(15-18)app-modules/user/src/Plugins/AppUserPanelPlugin.php (1)
getId(16-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Perform Pest Tests / Run
🔇 Additional comments (11)
composer.json (1)
143-145: Good approach for conditional debugbar loading.Adding
barryvdh/laravel-debugbartodont-discoveraligns with the manual conditional registration inAppServiceProvider. This prevents the debugbar from auto-registering in production and allows explicit control over when it's loaded.config/debugbar.php (2)
19-24: Safe default configuration.Setting
'enabled' => env('DEBUGBAR_ENABLED', false)ensures the debugbar is disabled by default, which is a safe production-friendly default. The exclusion oftelescope*andhorizon*routes is also appropriate.
247-249: Good exclusion of Filament views.Excluding
vendor/filamentfrom the views collector will reduce noise in the debugbar and improve performance during development. This is a thoughtful configuration choice.app/Providers/Tools/DebugbarServiceProvider.php (1)
11-23: Consider also overridingregister()if the goal is to fully disable debugbar.Currently, only
boot()is conditionally skipped, butparent::register()still runs (inherited behavior), which registers the debugbar bindings into the container. If you want to completely prevent debugbar initialization when disabled, you should also conditionally skipregister().If this is intentional (e.g., to allow runtime toggling), then this is fine. Otherwise, consider:
+ public function register(): void + { + if (! $this->canBoot()) { + return; + } + + parent::register(); + } + public function boot(): void { if (! $this->canBoot()) { return; } parent::boot(); }app/Providers/AppServiceProvider.php (2)
66-71: Defensive layered checks for debugbar registration.The
isLocal()check here combined with theconfig('debugbar.enabled')check inDebugbarServiceProviderprovides layered protection. This ensures debugbar is only loaded in local environments AND when explicitly enabled via config. Good defense-in-depth approach.
26-32: Clean separation of boot concerns.The refactoring to separate configuration into discrete methods (
configureDatabase,configureDates,configureVite,configureUrl) improves readability and maintainability. Each method has a single responsibility.database/seeders/ThreeDotsSeeder.php (1)
24-26: No issues found — field usage is intentional and correct for environment-specific seeding.Verification confirms both query patterns are appropriate:
- Production (
where('username', 'danielhe4rt')): Queries the production admin user, whose username is registered in config as an admin identifier.- Non-production (
where('name', 'admin')): Queries the seeded admin user created by BaseSeeder withname='admin'(andusername='admin').The User model supports both fields (confirmed in
app-modules/user/src/Models/User.phpfillable array), and the BaseSeeder creates the admin user with both fields set identically. This is an intentional design pattern for environment-specific seeding.app-modules/user/src/Plugins/AdminUserPanelPlugin.php (1)
11-11: LGTM! Widget registration is correct.The
UsersStatsOverviewwidget is properly imported and registered in the admin panel. This aligns with the cached statistics pattern implemented in the widget itself.Also applies to: 26-28
app-modules/user/src/Filament/Admin/Resources/Users/UserResource.php (1)
18-18: LGTM! Caching implementation is appropriate.The navigation badge now uses cached user counts with a 5-minute TTL, which will reduce database load. The use of
Number::abbreviate()provides a better UX for large user counts (e.g., "1.5K" instead of "1500").Also applies to: 21-21, 37-37
app-modules/user/src/Models/User.php (2)
128-134: LGTM! Panel access logic is correct.The explicit return of the match expression properly handles panel access control. The logic correctly restricts admin panel access to admins in production while allowing access in non-production environments for development/testing.
136-140: LGTM! Simplified avatar URL generation.The unconditional GitHub avatar URL generation is appropriate for this GitHub-centric application. Since
usernameis a required field, this simplification removes unnecessary conditional logic while maintaining functionality.
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Removals
✏️ Tip: You can customize this high-level summary in your review settings.