Coder Social home page Coder Social logo

Comments (12)

alexislefebvre avatar alexislefebvre commented on May 27, 2024

Please try these suggestions: #57 (comment)

from liiptestfixturesbundle.

dubitoph avatar dubitoph commented on May 27, 2024

Hello, I don't understand what I must try because my fixtures are in the src/Datafixtures repository.

from liiptestfixturesbundle.

dubitoph avatar dubitoph commented on May 27, 2024

In the fixture, I changed the Doctrine\Common\DataFixtures\FixtureInterface implementation to Doctrine\Common\DataFixtures\AbstractFixture implementation. I don't have anymore the previously error, but the data aren't saved in the database.

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on May 27, 2024

You need to persist data: https://symfony.com/doc/3.0/bundles/DoctrineFixturesBundle/index.html#writing-fixtures

Add this for every entity:

$manager->persist($user);
$manager->flush();

from liiptestfixturesbundle.

dubitoph avatar dubitoph commented on May 27, 2024

Of course! Really sorry for this mistake on my part and thank you very much for your help.

from liiptestfixturesbundle.

vulkanosaure avatar vulkanosaure commented on May 27, 2024

Add this for every entity:
$manager->persist($user);
$manager->flush();

are you saying that we need to flush inside the loop ?
flush is designed to be called only once at the end, or isn't that what you meant ?

edit : I also saw an article where someone was flushing in the loop, so I'm really curious if there is something i don't know about.
I don't wanna do it unless it's really necessary since that sounds like a waste of resource.

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on May 27, 2024

@vulkanosaure you can call flush() only once, it should work.

If you add tens or hundreds of entities, check the doc about Batch Processing: https://www.doctrine-project.org/projects/doctrine-orm/en/2.16/reference/batch-processing.html

See also this answer on Stack Overflow: https://stackoverflow.com/a/21335487/2257664 (spoiler: it's mine 😁)

from liiptestfixturesbundle.

vulkanosaure avatar vulkanosaure commented on May 27, 2024

thanks but why isn't using one single flush for a hundred of entities recommended ?
is it slower than the batch process you describe ? (eg: 10 flush that each handle 10 persist)

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on May 27, 2024

Adding hundreds of records then:

  • using only flush at the end may use a lot of RAM (hydrated entities can be pretty heavy). If I remember correctly Doctrine had performance issues when dealing with thousand of entities and the final flush was slow. It was about 10 years ago though so it may be better now
  • using flush on every iteration of the loop may be slower since it will perform many requests

Between these 2 cases, batch processing is a trade-off and it can help to not overwhelm Doctrine. It depends on the amount of data to be stored, so the first step is to test and see if you encounter performance issues, if that's the case then you can try different sizes for the batch. If you have no slowness when adding entities, keep one flush and move along.

from liiptestfixturesbundle.

vulkanosaure avatar vulkanosaure commented on May 27, 2024

ok, thanks for the insights !

from liiptestfixturesbundle.

vulkanosaure avatar vulkanosaure commented on May 27, 2024

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on May 27, 2024

@vulkanosaure Let's discuss this there:

from liiptestfixturesbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.