diff options
author | Stan Hu <stanhu@gmail.com> | 2018-10-31 22:51:11 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-11-01 17:19:54 +0300 |
commit | 0844ba04b518b4cd0a326a2ee0e8431eeb26950d (patch) | |
tree | e38a47efb50d4e701559ccb628cb009c3344f35d /spec/services/merge_requests/reload_diffs_service_spec.rb | |
parent | 98a504ecbb45907517ae465018906af7ef4573de (diff) |
Significantly cut memory usage and SQL queries when reloading diffs
By preloading certain models with the diff, we can eliminate many N+1
queries. For a push to the staging GitLab.com www-gitlab-com repository,
this eliminates over 3000 SQL queries and appears to bring down the RSS
usage by several gigabytes.
Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/49703
Diffstat (limited to 'spec/services/merge_requests/reload_diffs_service_spec.rb')
-rw-r--r-- | spec/services/merge_requests/reload_diffs_service_spec.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/spec/services/merge_requests/reload_diffs_service_spec.rb b/spec/services/merge_requests/reload_diffs_service_spec.rb index 21f369a3818..546c9f277c5 100644 --- a/spec/services/merge_requests/reload_diffs_service_spec.rb +++ b/spec/services/merge_requests/reload_diffs_service_spec.rb @@ -60,6 +60,17 @@ describe MergeRequests::ReloadDiffsService, :use_clean_rails_memory_store_cachin subject.execute end + + it 'avoids N+1 queries', :request_store do + current_user + merge_request + + control_count = ActiveRecord::QueryRecorder.new do + subject.execute + end.count + + expect { subject.execute }.not_to exceed_query_limit(control_count) + end end end end |