0

I am using DoctrineExtensions for managing a nested tree(nested tree behavior). I have to import 10-20K records from a csv file and store them in the database.

I created a service for this task which makes a bunch of new categories(tree nodes), sets the parents of these categories and persists them and in the end I call EntityManager#flush method to save the created categories into the database.

According to my logic, the process should go like this:

  1. The extension calculates the data needed for each node(right, left, level etc.)
  2. Doctrine makes a query in which it inserts all the data, similarly to this:

    INSERT INTO table (field1, field2, parent_id, root, left, ...) VALUES
    (fields of 1st record),
    (fields of 2st record),
    ...
    

However, Doctrine inserts each record separately, additionally root, left and right values get updated during the flush causing a huge amount of update queries to be needed.

For inserting 70 categories, I needed ~250 queries, when I wanted to add 500 categories, the program terminated due to memory shortage.

How could I optimize the process? Of course I could write it from scratch, but I'd really love to use this superb extension.

4

1 回答 1

1

我的解决方案是使用物化路径树而不是嵌套树。我知道,这不是这个问题的真正解决方案,但是它可以有效地工作。如果您有更好的解决方案,请发布,我可能会接受它作为解决方案。

于 2012-07-27T15:08:24.880 回答