我有以下 CrudController:
<?php
namespace App\Controller\Admin\Core;
use App\Entity\Core\Role;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\SlugField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class RoleCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Role::class;
}
public function configureFields(string $pageName): iterable
{
return [
TextField::new('name', 'Name')
->setRequired(true)
->setMaxLength(255)
->setHelp('The role name, prefix with: ROLE_'),
SlugField::new('systemName', 'System Name')
->setRequired(true)
->setTargetFieldName('name')->setFormattedValue(function ($value) {
return strtoupper($value);
}),
TextEditorField::new('description', 'Description'),
IntegerField::new('level', 'Role Level')->setHelp('Provide the role level'),
AssociationField::new('subsOfRole', 'Parent Role'),
ChoiceField::new('type', 'Role Relation Type')
->setChoices([
'User' => 1,
'Job Title' => 2,
'Unit' => 3,
'Office' => 4,
'Echelon' => 5,
'Office Type' => 6,
'user Group' => 7,
'Job Title Unit' => 8,
'Job Title Office' => 9,
'Job Title Unit Office' => 10,
'Job Title Unit Office Type' => 11
])
->setRequired(true),
AssociationField::new('users', 'Users')
->setHelp('Must be filled when you choose User as Role Relation Type')
->hideOnIndex(),
AssociationField::new('groups', 'Groups')
->setHelp('Must be filled when you choose Group as Role Relation Type')
->hideOnIndex(),
AssociationField::new('jobTitles', 'Job Title')
->hideOnIndex(),
AssociationField::new('units', 'Unit')
->hideOnIndex(),
AssociationField::new('offices', 'Offices')
->hideOnIndex(),
AssociationField::new('echelons', 'Echelons')
->hideOnIndex(),
AssociationField::new('officeTypes', 'Office Types')
->hideOnIndex(),
];
}
}
當我們有小資料時它運行良好,但是當我們將數萬個資料測驗到用戶物體/其他相關物體時,CRUD頁面非常慢。
有什么方法可以改變 associationField 的作業方式嗎?或者提高用戶端(瀏覽器)的性能?
背景關系: 我使用 Symfony 5.3.9 和 EasyAdmin 3.5.10,這是我寫這篇文章時的最新版本
謝謝
uj5u.com熱心網友回復:
正如 Will B. 所建議的,我檢查了自動完成功能并嘗試了它。這就是解決方案。
我以前的代碼變成了這樣(參見->autocomplete()實作):
<?php
namespace App\Controller\Admin\Core;
use App\Entity\Core\Role;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\SlugField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class RoleCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Role::class;
}
public function configureFields(string $pageName): iterable
{
return [
TextField::new('name', 'Name')
->setRequired(true)
->setMaxLength(255)
->setHelp('The role name, prefix with: ROLE_'),
SlugField::new('systemName', 'System Name')
->setRequired(true)
->setTargetFieldName('name')->setFormattedValue(function ($value) {
return strtoupper($value);
}),
TextEditorField::new('description', 'Description'),
IntegerField::new('level', 'Role Level')->setHelp('Provide the role level'),
AssociationField::new('subsOfRole', 'Parent Role')
->autocomplete(),
ChoiceField::new('type', 'Role Relation Type')
->setChoices([
'User' => 1,
'Job Title' => 2,
'Unit' => 3,
'Office' => 4,
'Echelon' => 5,
'Office Type' => 6,
'user Group' => 7,
'Job Title Unit' => 8,
'Job Title Office' => 9,
'Job Title Unit Office' => 10,
'Job Title Unit Office Type' => 11
])
->setRequired(true),
AssociationField::new('users', 'Users')
->autocomplete()
->setHelp('Must be filled when you choose User as Role Relation Type')
->hideOnIndex(),
AssociationField::new('groups', 'Groups')
->autocomplete()
->setHelp('Must be filled when you choose Group as Role Relation Type')
->hideOnIndex(),
AssociationField::new('jobTitles', 'Job Title')
->autocomplete()
->hideOnIndex(),
AssociationField::new('units', 'Unit')
->autocomplete()
->hideOnIndex(),
AssociationField::new('offices', 'Offices')
->autocomplete()
->hideOnIndex(),
AssociationField::new('echelons', 'Echelons')
->autocomplete()
->hideOnIndex(),
AssociationField::new('officeTypes', 'Office Types')
->autocomplete()
->hideOnIndex(),
];
}
}
現在負載很好。
謝謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/350072.html
標籤:php symfony symfony5 易管理员 易管理员3
上一篇:DoctrineQueryBuilder-ManyToMany-NOTIN-如何僅過濾關系不包含ID的物體?
下一篇:每次遷移都會改變uuid列的學說
