0

我有以下 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,这是我写这篇文章时的最新版本

谢谢

4

1 回答 1

0

正如 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(),
        ];
    }
}

现在负载很好。

谢谢

于 2021-11-03T17:59:10.697 回答