D
D
drboboev2018-11-07 12:02:07
MySQL
drboboev, 2018-11-07 12:02:07

What is the best way to organize entities in Doctrine?

Good afternoon.
There is an application that is designed for sales planning.
There is a list of territories (entity: Territory)
There is a list of products (entity: Product)
There is a record type (primary sales, secondary sales, batteries) (entity: EntryType)
There are records themselves (entity: Entry)
Application task: based on actual data, calculate according to the formula (and many other things) plans for the next year for each product and for each territory.
I took Excel-Bundle for parsing excel files. It was decided to download actual data from excel files for each territory for the year.
As a result, there is so much data that there are quite a lot of requests to the database. While I think, is it possible to change the entities, or maybe even the approach to this task itself. Therefore, I ask for advice on how best to organize entities for this task.
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Olga Svistunova, 2018-11-08
@drboboev

It's not entirely clear, "many" is how much? How many requests? Insert, update, select with a bunch of joins?
I can assume that since the parsing of excel files is mentioned, then insert queries are meant, but doctrine in symphony can do "persist many times, flush once" to optimize data insertion into the database with one query.
If, when building some data-graphics, you need a lot of data, then there are options with caching, with data processing in parallel in background processes (Enqueue Bundle, for example). Actually, with a long import, it can also be used.

F
FanatPHP, 2018-11-07
@FanatPHP

For such a short description, the entities are designed correctly.
What does the number of queries in the database have to do with this is a mystery.

D
drboboev, 2018-11-09
@drboboev Автор вопроса

FanatPHP , Ольга Свистунова insert запросы при парсинге. У меня сущность Entry содержала в себе поля product_id, territory_id, month, sum что означает, что записи записывались отдельно по каждой территории/месяцу/продукту/типу записи отдельной строкой в БД. И при записи получается много запросов и при выборке уже имеющихся данных из БД получается затратно.
Решил сделать иначе, изменил month на year, изменил тип поля sum с int на json_array, храню в БД одной строкой данные за весь год, при грубом расчёте количество запросов к БД при insert сократилось в 12 раз. и при выборке тоже, именно время взаимодействия с БД сократилось, в контроллере происходит конвертация json в array, что не занимает много времени.
Не знаю, можно ли еще как то оптимизировать количество запросов и скорость выполнения.
P.S. При insert запросе "flush" один.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question