doctrine / DoctrineFixturesBundle

Symfony integration for the doctrine/data-fixtures library
MIT License
2.44k stars 201 forks source link

In verbose mode, add the execution time of fixtures #445

Open florentdestremau opened 2 weeks ago

florentdestremau commented 2 weeks ago

Hi, I did a local trick to try and optimize our fixtures performance, it's pretty nice to see where you fixture time is going.

image

The trick is as simple as it gets, but I wonder how I could enable this only in verbose mode:

//src/Executor/ORMExecutor.php

    public function execute(array $fixtures, $append = false)
    {
        $executor = $this;
        $this->em->wrapInTransaction(static function (EntityManagerInterface $em) use ($executor, $fixtures, $append) {
            if ($append === false) {
                $executor->purge();
            }

            foreach ($fixtures as $fixture) {
                $start = microtime(true);
                $executor->load($em, $fixture);
                $end = microtime(true);
                $executionTime = $end - $start;
                echo 'Execution Time: ' . $executionTime . PHP_EOL;
            }
        });
    }

My issue here is that it's overlapping the bundle and the library and I don't see any easy hook to catch.

greg0ire commented 2 weeks ago

You could instead write a decorator implementing FixtureInterface, then decorate each fixture when gathering them?

florentdestremau commented 2 weeks ago

good idea, will dig it. One thing this could have led to is having the total time spent as well (locally I use time bin/console (...)