Symfony 5学说齐平慢了

发布于 2025-02-11 18:48:44 字数 194 浏览 1 评论 0原文

我只是想知道为什么随着时间的推移更新唱片(齐平)会减慢。 例如,如果我想检查mulitple记录并将它们与彼此进行比较,并且在比较之后更新了诸如setCompared(true)之类的列。前1000张唱片既可以又快,但是在那之后,每次冲洗后的冲洗似乎会变慢。是否有这样的理由,例如它可以建立或其他原因。 flush()之后,我需要清除()。

有人对此有解释吗?

I was just wondering why updating a record (flush) slows down over time.
For example, if i want to check mulitple records and compare them with eachother and after comparisation update a column like setCompared(true);. The first 1000 records are fine and fast but after that, the flush seems like it slows down after each flush. Is there a reason for that, like maybe it builds up or something. Do i need to clear() after flush().

Does anyone have a explaination for that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月光色 2025-02-18 18:48:44

您应该根据 Doctrine文档)

<?php

$batchSize = 20;
for ($i = 1; $i <= 10000; ++$i) {
    $user = new CmsUser;
    $user->setStatus('user');
    $user->setUsername('user' . $i);
    $user->setName('Mr.Smith-' . $i);
    $em->persist($user);
    if (($i % $batchSize) === 0) {
        $em->flush();
        $em->clear(); // Detaches all objects from Doctrine!
    }
}
$em->flush(); // Persist objects that did not make up an entire batch
$em->clear();

以下代码显示了一个插入10000个对象的示例,其批次大小为20。这意味着我们使用flush()。

You should do something like this according to the Doctrine documentation) :

<?php

$batchSize = 20;
for ($i = 1; $i <= 10000; ++$i) {
    $user = new CmsUser;
    $user->setStatus('user');
    $user->setUsername('user' . $i);
    $user->setName('Mr.Smith-' . $i);
    $em->persist($user);
    if (($i % $batchSize) === 0) {
        $em->flush();
        $em->clear(); // Detaches all objects from Doctrine!
    }
}
$em->flush(); // Persist objects that did not make up an entire batch
$em->clear();

The following code shows an example for inserting 10000 objects with a batch size of 20. This means that we insert them 20 by 20 with the flush().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文