簡體   English   中英

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()實現):

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

現在負載很好。

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM