Skip to content

Commit cee7ad0

Browse files
committed
Refactor KerangkaAcuan resource to remove unnecessary eager loading and update AppServiceProvider to handle lazy loading violations with logging
1 parent b92303d commit cee7ad0

File tree

4 files changed

+8
-70
lines changed

4 files changed

+8
-70
lines changed

app/Nova/KerangkaAcuan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
class KerangkaAcuan extends Resource
3636
{
37-
public static $with = ['unitKerja', 'naskahKeluar', 'arsipDokumen', 'anggaranKerangkaAcuan', 'spesifikasiKerangkaAcuan', 'daftarSp2d'];
37+
public static $with = ['unitKerja', 'arsipDokumen', 'anggaranKerangkaAcuan', 'spesifikasiKerangkaAcuan', 'daftarSp2d'];
3838

3939
public static function label()
4040
{

app/Providers/AppServiceProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace App\Providers;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\Facades\URL;
67
use Illuminate\Support\ServiceProvider;
8+
use Log;
79

810
class AppServiceProvider extends ServiceProvider
911
{
@@ -24,5 +26,10 @@ public function boot(): void
2426
URL::forceRootUrl(env('APP_URL'));
2527
URL::forceScheme('https');
2628
}
29+
Model::preventLazyLoading();
30+
Model::handleLazyLoadingViolationUsing(function ($model, $relation) {
31+
Log::warning(sprintf('N+1 Query detected in %s::%s', get_class($model), $relation));
32+
});
33+
2734
}
2835
}

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
],
2323
"require": {
2424
"php": "^8.2",
25-
"beyondcode/laravel-query-detector": "*",
2625
"fidum/laravel-nova-metrics-polling": "^1.0",
2726
"fidum/nova-package-bundler-command": "^1.8",
2827
"intervention/image-laravel": "*",

config/querydetector.php

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)