Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some widgets take a long time before appearing #1069

Closed
alexislefebvre opened this issue May 29, 2018 · 4 comments
Closed

Some widgets take a long time before appearing #1069

alexislefebvre opened this issue May 29, 2018 · 4 comments

Comments

@alexislefebvre
Copy link
Member

alexislefebvre commented May 29, 2018

Description

I try to modify a widget Menu. The server returns a response after 93 seconds.

I can't open the dropdowns.

Resolution Ideas

It may be due to the fact that this website contain more than 5000 pages, so the dropdown where we select a site's page take a really long time to be generated.

We could use something like select2 in order to lazy-load the list of pages.

Related to

Bundle -- -- --
Analytics Page
Blog Query
BusinessEntity Seo
BusinessPage Sitemap
Core Template
Criteria Twig
Filter User
Form ViewReference
I18n Widget
Media WidgetMap
UI
alexislefebvre added a commit to alexislefebvre/victoire that referenced this issue May 30, 2018
@alexislefebvre alexislefebvre self-assigned this May 31, 2018
@alexislefebvre
Copy link
Member Author

I added select2 in order to select pages but I'm stuck since Redis doesn't allow full text search.

There are workarounds but they are not simple:

@alexislefebvre
Copy link
Member Author

We need a simple and effective solution, my solutions are not good enough.

@alexislefebvre
Copy link
Member Author

We may try to filter data on server side with PHP: generate all the tree bur return only the pages that match with the AJAX search.

@alexislefebvre
Copy link
Member Author

We used an alternative solution in order to replace the service that create choices:

app/config/services.yml:

    # overload service in order to remove business pages
    victoire_view_reference.repository:
        class: Victoire\Bundle\ViewReferenceBundle\Connector\ViewReferenceWithoutBusinessPagesRepository
        arguments:
            - "@victoire_view_reference.connector.repository"
            - "@victoire_view_reference.transformer_chain"

/src/Victoire/Bundle/ViewReferenceBundle/Connector/ViewReferenceWithoutBusinessPagesRepository.php:

<?php

namespace Victoire\Bundle\ViewReferenceBundle\Connector;

use Victoire\Bundle\ViewReferenceBundle\Builder\Chain\ViewReferenceTransformerChain;
use Victoire\Bundle\ViewReferenceBundle\Transformer\ArrayToBusinessPageReferenceTransformer;

/**
 * Overload the “getChoices” method in order to remove business pages from choices.
 */
class ViewReferenceWithoutBusinessPagesRepository extends ViewReferenceRepository
{
    private $repository;
    private $transformer;

    /**
     * ViewReferenceManager constructor.
     *
     * @param ViewReferenceConnectorRepositoryInterface $repository
     * @param ViewReferenceTransformerChain             $transformer
     */
    public function __construct(ViewReferenceConnectorRepositoryInterface $repository, ViewReferenceTransformerChain $transformer)
    {
        $this->repository = $repository;
        $this->transformer = $transformer;

        parent::__construct($repository, $transformer);
    }

    /**
     * {@inheritdoc}
     */
    public function getChoices($locale, $refId = null, $depth = 0)
    {
        $viewsReferences = [];

        $decoratorFn = function ($depth, $char0 = '└', $char = '─') {
            $decorator = $char0;
            for ($i = 0; $i <= $depth; ++$i) {
                $decorator .= $char;
            }

            return $decorator;
        };

        if (null === $refId) {
            $refsId = $this->repository->getAllBy([
                'locale' => $locale,
                'slug' => '',
            ]);
        } else {
            $refsId = $this->repository->getAllBy([
                'locale' => $locale,
                'parent' => $refId,
            ]);
        }
        $refs = $this->repository->getResults($refsId);

        foreach ($refs as $reference) {
            $viewReferenceTransformer = ViewReferenceManager::findTransformerFromElement($reference);

            // Patch: Ignore business pages
            if ($viewReferenceTransformer instanceof ArrayToBusinessPageReferenceTransformer) {
                continue;
            }

            $viewReference = $viewReferenceTransformer->transform($reference);
            if ($viewReference->getName() != '') {
                $decorator = '';
                if ($depth > 0) {
                    $decorator = $decoratorFn($depth).' ';
                }
                $viewsReferences[$decorator.$viewReference->getName()] = $viewReference->getId();
            }

            $viewsReferences = array_merge($viewsReferences, $this->getChoices($locale, $viewReference->getId(), $depth + 1));
        }

        return $viewsReferences;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant