Skip to content
代码片段 群组 项目
未验证 提交 4646dc6e 编辑于 作者: Terri Chu's avatar Terri Chu 提交者: GitLab
浏览文件

Merge branch 'tchu-update-each_batch_range-example-in-docs' into 'master'

Update each_batch_range example in dev docs

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/184340



Merged-by: default avatarTerri Chu <tchu@gitlab.com>
Approved-by: default avatarFabien Catteau <fcatteau@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -1450,15 +1450,13 @@ Be aware of the limitations [when using models in migrations](#using-application ...@@ -1450,15 +1450,13 @@ Be aware of the limitations [when using models in migrations](#using-application
In most circumstances, prefer migrating data in **batches** when modifying data in the database. In most circumstances, prefer migrating data in **batches** when modifying data in the database.
We introduced a new helper [`each_batch_range`](https://gitlab.com/gitlab-org/gitlab/-/blob/cd3e0a5cddcb464cb9b8c6e3275839cf57dfa6e2/lib/gitlab/database/dynamic_model_helpers.rb#L28-32) which facilitates the process of iterating over a collection in a performant way. The default size of the batch is defined in the `BATCH_SIZE` constant. Use the helper [`each_batch_range`](https://gitlab.com/gitlab-org/gitlab/blob/d430ac7e5b994a4328d648302f85e8d47ed41e11/lib/gitlab/database/migration_helpers.rb#L52-52) which facilitates the process of iterating over a collection in a performant way. The default size of the batch is defined in the `BATCH_SIZE` constant.
See the following example to get an idea. See the following example to get an idea.
**Purging data in batch:** **Purging data in batch:**
```ruby ```ruby
include ::Gitlab::Database::DynamicModelHelpers
disable_ddl_transaction! disable_ddl_transaction!
def up def up
...@@ -1479,7 +1477,7 @@ end ...@@ -1479,7 +1477,7 @@ end
- The second argument calls a lambda which fetches the relevant dataset selected (the default is set to `.all`): `scope: ->(table) { table.ref_protected }`. - The second argument calls a lambda which fetches the relevant dataset selected (the default is set to `.all`): `scope: ->(table) { table.ref_protected }`.
- The third argument is the batch size (the default is set in the `BATCH_SIZE` constant): `of: BATCH_SIZE`. - The third argument is the batch size (the default is set in the `BATCH_SIZE` constant): `of: BATCH_SIZE`.
Here is an [example MR](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62195) illustrating how to use our new helper. Here is an [example MR](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/171528) illustrating how to use the helper.
## Using application code in migrations (discouraged) ## Using application code in migrations (discouraged)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册