summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-07-08 14:16:42 +0000
committerRémy Coutable <remy@rymai.me>2016-07-08 14:16:42 +0000
commit7dba769886e662d4a5701285421f6e75b917d1eb (patch)
tree57b86632e9abddb73e8a0b8d7760e3d806bc9ab0
parentad806f32dc368ee10b6a9b79d7f2ec7b42644311 (diff)
parent52a89f20229285183eb6ecc9e9da444d004be5b3 (diff)
downloadgitlab-ce-7dba769886e662d4a5701285421f6e75b917d1eb.tar.gz
Merge branch 'memoize_merge_request_events' into 'master'
Memoize MR merged/closed events retrieval ## What does this MR do? Memoize a database call that is execute 3 consecutive times ## Why was this MR needed? To speed up MR pages ## What are the relevant issue numbers? #14202 , #19490 ## Screenshots (if relevant) The query is fast most of the times, but we can avoid the 3 call counts to the database ![Screen_Shot_2016-07-08_at_12.49.48](/uploads/ab0f6d843be30754a06e0f05bdf2102d/Screen_Shot_2016-07-08_at_12.49.48.png) ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - ~~[ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~ - ~~[ ] API support added~~ - Tests - ~~[ ] Added for this feature/bug~~ - [ ] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5151
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/merge_request.rb4
2 files changed, 3 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 09f2c44e02c..f6fb9b7d257 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -45,6 +45,7 @@ v 8.10.0 (unreleased)
- RailsCache metris now includes fetch_hit/fetch_miss and read_hit/read_miss info.
- Allow [ci skip] to be in any case and allow [skip ci]. !4785 (simon_w)
- Set import_url validation to be more strict
+ - Memoize MR merged/closed events retrieval
- Add basic system information like memory and disk usage to the admin panel
- Don't garbage collect commits that have related DB records like comments
- More descriptive message for git hooks and file locks
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 083e93f1ee7..393d8a72657 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -318,11 +318,11 @@ class MergeRequest < ActiveRecord::Base
end
def merge_event
- self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last
+ @merge_event ||= target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last
end
def closed_event
- self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
+ @closed_event ||= target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
end
WIP_REGEX = /\A\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i.freeze