Mikołaj Różański
Mikołaj Różański
TCTwill CMS
Created by Mikołaj Różański on 2/6/2024 in #👊support
"astrotomic/laravel-translatable" n+1 queries
No description
11 replies
TCTwill CMS
Created by Mikołaj Różański on 2/6/2024 in #👊support
"astrotomic/laravel-translatable" n+1 queries
In the case of the lessons it is the following:
$lesson_list = Lesson::join('lesson_translations', function($join) {
$join->on('lessons.id', '=', 'lesson_translations.lesson_id')
->where('lesson_translations.locale', app()->getLocale())
->where('lesson_translations.title', '!=', "")
->whereNotNull('lesson_translations.title');
})
->join('twill_related', 'lessons.id', '=', 'twill_related.related_id')
->where('related_type', 'App\Models\Lesson')
->where('subject_type', 'App\Models\Course')
->where('lessons.published', 1)
->orderBy('twill_related.position', 'ASC')
->select([
'lessons.*',
'lesson_translations.title AS title',
'lessons.url AS url',
'lesson_translations.lesson_id AS lesson_id',
'twill_related.subject_id AS subject_id',
'twill_related.position AS position'
])
->get();

foreach ($temp_courses as $temp_course) {
$lessons[] = $lesson_list->where('subject_id', $temp_course->course_id);
}

$lesson_list = Lesson::join('lesson_translations', function($join) {
$join->on('lessons.id', '=', 'lesson_translations.lesson_id')
->where('lesson_translations.locale', app()->getLocale())
->where('lesson_translations.title', '!=', "")
->whereNotNull('lesson_translations.title');
})
->join('twill_related', 'lessons.id', '=', 'twill_related.related_id')
->where('related_type', 'App\Models\Lesson')
->where('subject_type', 'App\Models\Course')
->where('lessons.published', 1)
->orderBy('twill_related.position', 'ASC')
->select([
'lessons.*',
'lesson_translations.title AS title',
'lessons.url AS url',
'lesson_translations.lesson_id AS lesson_id',
'twill_related.subject_id AS subject_id',
'twill_related.position AS position'
])
->get();

foreach ($temp_courses as $temp_course) {
$lessons[] = $lesson_list->where('subject_id', $temp_course->course_id);
}

11 replies
TCTwill CMS
Created by Mikołaj Różański on 2/6/2024 in #👊support
"astrotomic/laravel-translatable" n+1 queries
this page same page also calls years, courses, lessons and twill related but dont think this matters towards the problem
11 replies
TCTwill CMS
Created by Mikołaj Różański on 2/6/2024 in #👊support
"astrotomic/laravel-translatable" n+1 queries
And this is my test calling directly without twill dependencies:
/*
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Lesson extends Model
{
use HasFactory;

protected $table = 'lessons';
protected $primaryKey = 'id';
}
*/
/*
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Lesson extends Model
{
use HasFactory;

protected $table = 'lessons';
protected $primaryKey = 'id';
}
*/
11 replies
TCTwill CMS
Created by Mikołaj Różański on 2/6/2024 in #👊support
"astrotomic/laravel-translatable" n+1 queries
With Twill models the model for lessons looks like this
<?php

namespace App\Models;

use A17\Twill\Models\Behaviors\HasTranslation;
use A17\Twill\Models\Behaviors\HasPosition;
use A17\Twill\Models\Behaviors\Sortable;
use A17\Twill\Models\Behaviors\HasMedias;
use A17\Twill\Models\Behaviors\HasFiles;
use A17\Twill\Models\Behaviors\HasRelated;
use A17\Twill\Models\Model;

class Lesson extends Model implements Sortable
{
use HasTranslation, HasPosition, HasMedias, HasFiles, HasRelated;

protected $fillable = [
'published',
'position',
'title',
'description',
'position',
'url',
];

public $translatedAttributes = [
'active',
'title',
'description',
];

public $mediasParams = [
'lesson_image' => [
'default' => [
[
'name' => 'free',
'ratio' => 0
]
]
]
];
<?php

namespace App\Models;

use A17\Twill\Models\Behaviors\HasTranslation;
use A17\Twill\Models\Behaviors\HasPosition;
use A17\Twill\Models\Behaviors\Sortable;
use A17\Twill\Models\Behaviors\HasMedias;
use A17\Twill\Models\Behaviors\HasFiles;
use A17\Twill\Models\Behaviors\HasRelated;
use A17\Twill\Models\Model;

class Lesson extends Model implements Sortable
{
use HasTranslation, HasPosition, HasMedias, HasFiles, HasRelated;

protected $fillable = [
'published',
'position',
'title',
'description',
'position',
'url',
];

public $translatedAttributes = [
'active',
'title',
'description',
];

public $mediasParams = [
'lesson_image' => [
'default' => [
[
'name' => 'free',
'ratio' => 0
]
]
]
];
11 replies
TCTwill CMS
Created by Mikołaj Różański on 9/7/2023 in #👊support
Adding role and permission for single module
We will hold off on the task then for now, I hope it can be implemented in an upcoming release.
6 replies
TCTwill CMS
Created by Mikołaj Różański on 9/7/2023 in #👊support
Adding role and permission for single module
would it be a good idea to update twill to have the twill_ prefix before on those aswell?
6 replies
TCTwill CMS
Created by Mikołaj Różański on 9/7/2023 in #👊support
Adding role and permission for single module
I presume this is generating a roles and groups tables - i already have modules with those names so its conflicting
6 replies