diff options
author | Stan Hu <stanhu@gmail.com> | 2018-04-27 05:45:22 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-05-25 02:40:02 +0300 |
commit | 760fdd1dd31d30d5ab407a0c42e864040d79504c (patch) | |
tree | db19fdc919e7492d2cd57b83b53d91a3da6f4b7a /app/services | |
parent | ba58a66a55e2270eb46f7429e070d16f77d25b9d (diff) |
Fix project destruction failing due to idle in transaction timeouts
When deleting associated records, Rails loads all associations into memory
(https://github.com/rails/rails/issues/22510) before destroying them. This
can cause a surge in memory and cause destruction of objects to fail
due to idle in transaction database timeouts. This fix is inspired from
https://github.com/thisismydesign to destroy `has_many` relationships
in batches.
Closes #44610
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/destroy_service.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb index adbc498d0bf..04a293a0fd6 100644 --- a/app/services/projects/destroy_service.rb +++ b/app/services/projects/destroy_service.rb @@ -124,7 +124,13 @@ module Projects trash_repositories! - project.team.truncate + # Rails attempts to load all related records into memory before + # destroying: https://github.com/rails/rails/issues/22510 + # This ensures we delete records in batches. + # + # Exclude container repositories because its before_destroy would be + # called multiple times, and it doesn't destroy any database records. + project.destroy_dependent_associations_in_batches(exclude: [:container_repositories]) project.destroy! end end |