通过 MySQL 查询插入 Symfony NestedSet 数据

发布于 2024-12-19 00:11:28 字数 435 浏览 5 评论 0原文

在 Symfony 探索项目中,我有一个使用 NestedSet 行为原则的模型。由于数据是在平面文件中准备的,因此我编写了 转换实用程序生成相应的YAML。事实证明,处理大约 100 条记录(max_深度 = 4)的 NestedSet YML 消耗了超过 40MB 的 PHP 内存,这对我来说是无法使用的。

这个问题有解决方法吗?

我正在考虑两种可能的解决方案。

  1. 编写一个等效的 PHP 脚本来填充对象和对象保存它们
  2. 通过 SQL 语句插入数据,挑战在于计算左值和右值。正确的节点

Symfonians 有什么建议?

On a Symfony exploration project, I have a model using doctrine NestedSet behaviour. Since the data is prepared in a flat file, I wrote a conversion utility to generate corresponding YAML. It turns out that processing NestedSet YML of around 100 records (max_depth=4) consumes over 40MB of PHP memory, which is not available to me.

Is there a work-around to this problem?

I'm thinking of 2 possible solutions.

  1. Write an equivalent PHP script to populate objects & save them
  2. Insert data via SQL statements, the challenge being to compute the left & right nodes

What do Symfonians suggest?

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

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

发布评论

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

评论(2

与风相奔跑 2024-12-26 00:11:28

我建议您多次插入数据,例如从级别 0 开始,每个级别插入一次。

I suggest you insert the data in several times, one time per level starting at level 0, for instance.

风和你 2024-12-26 00:11:28

选项 2 更好。

我在 Excel 中编写了一个简单的宏来计算前序树所需的 lgt 和 rgt 值。这里提到的逻辑: http://www.sitepoint.com/hierarchical-data-database -2/
同一个 Excel 实用程序会将值转换为可通过文件转储的 SQL 查询。

遍历灯具/对象路径超出了允许的内存限制。

Option 2 was better.

I wrote a simple macro in Excel to compute the lgt and rgt values required for the pre-order tree. Logic as mentioned here: http://www.sitepoint.com/hierarchical-data-database-2/
The same Excel utility would convert values to a SQL query that could be dumped via file.

Going through the fixtures/object route exceeded the allowed memory limit.

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