拉拉维尔(Laravel)的块和分页有什么区别?

发布于 2025-02-08 05:34:05 字数 306 浏览 1 评论 0原文

我已经阅读了一些文章,但我仍然感到困惑。 在加载页面时,它将执行查询,但是中会发生什么? 我阅读 https://laravel-school.com/posts/posts/posts/laravel-laravel-laravel-laravel-laravel-分页-VS-Chunk-51 本文等等。

I already read some article but I am still confused.
I n pagination it will execute a query when load a page but what happen in chunk ?
I read https://laravel-school.com/posts/laravel-pagination-vs-chunk-51 this article and so on.

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

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

发布评论

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

评论(1

攒一口袋星星 2025-02-15 05:34:05

现在,分页在每个页面上起作用。因此,例如,如果您有100个记录,并且每页检索10个记录,则需要执行10个查询才能获取所有结果。但是,由于它是分页,因此您使用一个页码来确定将返回的记录。例如,第3页将返回记录21-30,依此类推。在这里,您始终只会在内存中加载10个记录并将其返回。查询明智的操作以限制和偏移来确定正确的记录。

现在看块实际上有些不同。因此,如果我们仍然记录了100个记录,并且我们通过10个记录将它们放置,我们仍然可以解析所有100个记录。但是,一次只会在内存中加载10个记录。因此,它使用限制和偏移使用类似的查询方法,但是它最终将返回所有结果,但是在批处理/块中,而不仅仅是返回1组记录。

该文档还很好地解释了这一点: https://lararavel.com /docs/9.x/eloquent#chunking-results

Now pagination works on a per page basis. So if you for example have 100 records and you retrieve 10 records per page you need to perform 10 queries to get all results. However since it's pagination you have a page number you use to determine which records you will return. For example page 3 will return the records 21-30 and so on. Here you will always only load 10 records in memory and return them. Query wise this works with a limit and offset to determine the correct records.

Now looking at chunk it's actually a bit different. So if we still take the 100 records and we chunk them by 10 records we still parse all the 100 records. However it will only load 10 records in memory at a time. So it's using a similar query approach using limit and offset, however it will eventually return all results, but in batches/chunks instead of only return 1 set of records.

The documentation also does a good job of explaining this: https://laravel.com/docs/9.x/eloquent#chunking-results

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