Symfony 5 - Easy Admin 3:当关联实体有这么多数据时,AssociationField 的负载很重
Symfony 5 - Easy Admin 3: Heavy load on AssociationField when the associated entity have so many data
我有以下 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,这是我写这篇文章时的最新版本
谢谢
根据 Will B. 的建议,我检查了 autocomplete 功能并尝试了它。这就是解决方案。
我之前的代码变成了这样(参见 ->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(),
];
}
}
现在负载很好
谢谢
我有以下 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,这是我写这篇文章时的最新版本
谢谢
根据 Will B. 的建议,我检查了 autocomplete 功能并尝试了它。这就是解决方案。
我之前的代码变成了这样(参见 ->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(),
];
}
}
现在负载很好
谢谢