Skip to content

Cache project integration records

What does this MR do and why?

Related to &7290 (comment 1168968775)

It defines integrations.public_send(hooks_scope) as relations on project because they load the records on each invocation and we call the execute_integrations method a few(hundred?) times when creating a pipeline:

 "SELECT \"integrations\".* FROM \"integrations\" WHERE \"integrations\".\"project_id\" = 278964 AND \"integrations\".\"job_events\" = TRUE AND \"integrations\".\"active\" = TRUE" => 166

Backtrace:

   "lib/peek/views/active_record.rb:55:in `block in setup_subscribers'",
   "app/models/project.rb:1693:in `block in execute_integrations'",
   "app/models/concerns/after_commit_queue.rb:29:in `instance_eval'",
   "app/models/concerns/after_commit_queue.rb:29:in `run_after_commit_or_now'",
   "app/models/project.rb:1692:in `execute_integrations'",
   "app/models/ci/build.rb:780:in `execute_hooks'",
   "app/models/ci/build.rb:207:in `block (2 levels) in <class:Build>'",
   "app/models/concerns/after_commit_queue.rb:39:in `instance_eval'",
   "app/models/concerns/after_commit_queue.rb:39:in `_run_after_commit_queue'",
   "lib/gitlab/database.rb:332:in `block in transaction'",
   "lib/gitlab/database.rb:331:in `transaction'",
   "app/models/concerns/cross_database_modification.rb:83:in `transaction'",
   "lib/gitlab/ci/pipeline/chain/create.rb:15:in `block (3 levels) in perform!'",
   "app/models/concerns/ci/bulk_insertable_tags.rb:13:in `with_bulk_insert_tags'",
   "lib/gitlab/ci/pipeline/chain/create.rb:14:in `block (2 levels) in perform!'",
   "app/models/concerns/bulk_insertable_associations.rb:54:in `with_bulk_insert'",
   "lib/gitlab/ci/pipeline/chain/create.rb:13:in `block in perform!'",
   "lib/gitlab/ci/pipeline/logger.rb:33:in `instrument'",
   "lib/gitlab/ci/pipeline/logger.rb:43:in `instrument_with_sql'",
   "lib/gitlab/ci/pipeline/chain/create.rb:12:in `perform!'",
   "lib/gitlab/ci/pipeline/chain/sequence.rb:20:in `block in build!'",
   "lib/gitlab/ci/pipeline/chain/sequence.rb:16:in `each'",
   "lib/gitlab/ci/pipeline/chain/sequence.rb:16:in `build!'",
   "app/services/ci/create_pipeline_service.rb:98:in `execute'",
   "ee/app/services/ee/merge_requests/create_pipeline_service.rb:32:in `create_merged_result_pipeline_for'",
   "ee/app/services/ee/merge_requests/create_pipeline_service.rb:10:in `execute'",
   "lib/api/merge_requests.rb:413:in `block (2 levels) in <class:MergeRequests>'",
   "ee/lib/gitlab/ip_address_state.rb:10:in `with'",
   "lib/api/api_guard.rb:215:in `call'",
   "ee/lib/omni_auth/strategies/group_saml.rb:41:in `other_phase'",
   "lib/gitlab/jira/middleware.rb:19:in `call'",
   "lib/gitlab/database/query_analyzer.rb:37:in `within'"

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marius Bobin

Merge request reports