diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-08 19:10:46 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-15 19:54:23 +0300 |
commit | 8a9164bf04fe20bfee9ea7923c655f4600e88c7f (patch) | |
tree | 61020f184356de6f2f62fbd32d939299ee46220f | |
parent | af493ccf3658c9f8b1266a880eb1798fe30cb324 (diff) |
Set inverse_of for Project/Services relation
This ensures that code such as this don't run needless SQL queries:
project.gitlab_issue_tracker_service.project
This also means that if the root `project` eager loads any associations
the Service object will be able to re-use those.
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | app/models/service.rb | 2 |
3 files changed, 3 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index bb5bde9b08b..b767996bc82 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -99,6 +99,7 @@ v 8.9.0 (unreleased) - Remove tanuki logo from side navigation; center on top nav - Include user relationships when retrieving award_emoji - Various associations are now eager loaded when parsing issue references to reduce the number of queries executed + - Set inverse_of for Project/Service association to reduce the number of queries v 8.8.5 (unreleased) - Ensure branch cleanup regardless of whether the GitHub import process succeeds diff --git a/app/models/project.rb b/app/models/project.rb index fdbc84474ed..0bb815e64e7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -81,7 +81,7 @@ class Project < ActiveRecord::Base has_one :jira_service, dependent: :destroy has_one :redmine_service, dependent: :destroy has_one :custom_issue_tracker_service, dependent: :destroy - has_one :gitlab_issue_tracker_service, dependent: :destroy + has_one :gitlab_issue_tracker_service, dependent: :destroy, inverse_of: :project has_one :external_wiki_service, dependent: :destroy has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" diff --git a/app/models/service.rb b/app/models/service.rb index bf352397509..40d39933ad8 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -18,7 +18,7 @@ class Service < ActiveRecord::Base after_commit :reset_updated_properties after_commit :cache_project_has_external_issue_tracker - belongs_to :project + belongs_to :project, inverse_of: :services has_one :service_hook validates :project_id, presence: true, unless: Proc.new { |service| service.template? } |