Skip to content

Insert a lot of data - batch processing #883

Description

@seb-jean

Hi,

I'd like to insert a lot of data into my User table, which contains many columns, but it's taking a long time. So I used another entity called Message, which has a few columns. Unfortunately, importing 1 million rows is also taking a long time. It's been going on for over an hour.
I'm wondering if it's possible to insert a lot of data with Foundy.
Would a batch processing solution offered by Doctrine be worth implementing in Foundry?
Thanks :).

<?php

namespace App\DataFixtures;

use App\Entity\User;
use App\Factory\MessageFactory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use function Zenstruck\Foundry\Persistence\repository;

use function Zenstruck\Foundry\Persistence\flush_after;

final class AppFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        flush_after(function () {
            $user1 = repository(User::class)->find(805);
            $user2 = repository(User::class)->find(804);

            MessageFactory::createMany(1000000, attributes: fn ($i) => [
                'sender' => $user1,
                'receiver' => $user2,
            ]);
        });
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions