Skip to content

Commit

Permalink
Limited eager loading of referenties on referentie_types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamieljv committed Jul 11, 2024
1 parent 393cad3 commit e1a8d2c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/ActieWijzerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Models\Theme;
use Artesaos\SEOTools\Facades\SEOTools;
use Artesaos\SEOTools\Facades\SEOMeta;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Expand Down Expand Up @@ -124,7 +125,9 @@ public function result(Request $request) {
});

// Get referentie_types and calculate the similarity with the score_vector
$referentie_types = ReferentieType::published()->get();
$referentie_types = ReferentieType::published()->with(['referenties' => function (Builder $query) {
$query->inRandomOrder()->limit(3);
}])->get();
foreach ($referentie_types as $rt) {
$dims_filtered = array_filter($dimensions->toArray(), function($d) use ($rt) {
return in_array($d['id'], array_keys($rt->score_vector));
Expand Down
1 change: 1 addition & 0 deletions app/Models/Referentie.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class Referentie extends Model
{
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;

protected $table = 'referenties';

Expand Down
3 changes: 2 additions & 1 deletion app/Models/ReferentieType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class ReferentieType extends Model
{

use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;

protected $table = 'referentie_types';

protected $fillable = [
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"matanyadaev/laravel-eloquent-spatial": "^4.2",
"mcordingley/linearalgebra": "^3.0",
"orangehill/iseed": "^3.0",
"staudenmeir/eloquent-eager-limit": "^1.8",
"tcg/voyager": "^1.7",
"tymon/jwt-auth": "^2.1"
},
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions resources/views/actiewijzer/result.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</a>
</div>

<div class="max-w-6xl mx-auto mt-6 mb-40 px-5 lg:px-0">
<div class="max-w-6xl mx-auto mt-6 mb-40 px-0">
<div id="app" class="p-8 bg-white rounded-md shadow-md min-h-[400px]">

<h1 class="md:text-6xl text-center">{{ __('actiewijzer.results_header') }}</h1>
Expand Down Expand Up @@ -101,7 +101,7 @@ class="relative self-start inline-block px-2 py-1 mr-1 mb-1 text-xs font-medium
>
</actie-agenda>
@else
<div class="grid gap-5 mx-auto mt-12 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<div class="grid gap-5 mx-auto mt-12 sm:grid-cols-2 lg:grid-cols-3">
@foreach ($rt->referenties->toArray() as $ref)
<Referentie
:referentie="{{json_encode($ref)}}"
Expand Down

0 comments on commit e1a8d2c

Please sign in to comment.