1

I've got Movie entity, which has ManyToMany connections with such entities as Actor, Director, Producer,Company` etc.

There are lots of those entities (Actor: 90k, Director: 40k, Producer: 20k, Company: 40k) to choose from, when editing the Movie.

When I try to load the "edit" page for my entity in Sonata Admin, I get error 500 and php logs say Allowed memory size of 134217728 bytes exhausted in one of the following files:

\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 2577
\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php on line 296
\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 529

It worked on fixtures, when there were like 10 objects in DB for every entity.

I'm currently testing migration and I assumed there will be a huge load of data on the edit page and the page itself may work slow (there will be four select2 fields, each multiple choice, each will have thousands of entities to connect to the edited entity), but I am surprised it happens on the Doctrine level. I was hoping Sonata Admin will handle it, as it has no problem with listing huge amount of Actor objects, pagination etc.

How should I arrange working with Movie entity? Can you advise me something? I'm thinking of changing that CRUD page so Select2 would fetch data with Ajax, but I'm still not sure it's a best idea.

Community
  • 1
  • 1
b174008
  • 285
  • 3
  • 13

2 Answers2

0

you need to think about how the application will be used. In your edit panel do you think a list of all the possible relation (actors, director …) on your entity will be the best UX, i don't think so.

Your entity will fetch all the dependencies and hydrate them in object. You can see how it is a problem for your memory, even if you set the memory limit to 1To.

What I recommend is to use autocomplete. This way you will not load thousands of unuseful data, the application will be much faster and the user will be able to search what he's looking for instead of searching in an endless select box.

Hope it helps.

  • Yep, I'm working on autocomplete right now. I've made api action for search, the only problem is Sonata customization, which is hell for me... EDIT: hopefully SONATA_TYPE_MODEL_AUTOCOMPLETE will help me. – b174008 Feb 22 '16 at 11:56
  • Finally - looks like it works with SONATA_TYPE_MODEL_AUTOCOMPLETE out of the box. Now I only have to change "user" side - I'll try PUGXAutocompleterBundle, maybe it will be painless. Thanks. – b174008 Feb 22 '16 at 12:37
-1

You can increase the memory_limit by adding more to php.ini

to find the correct one place phpInfo(); on top of your AppKernel.php and search for "php.ini" in the output, then edit the ini file and change the line ´memory_limit to 2G for example

also if possible you should avoid objecthydration (hydrating the result rows to entity) which causes the memory size to be exhausted, here are some infos abvout that

http://labs.octivi.com/mastering-symfony2-performance-doctrine/

john Smith
  • 17,409
  • 11
  • 76
  • 117