BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
1b65f905
Commit
1b65f905
authored
Dec 12, 2017
by
Sean McGivern
Committed by
Oswaldo Ferreira
Dec 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'zj-memoization-mr-commits' into 'master'
Use memoization for commits on diffs See merge request gitlab-org/gitlab-ce!15857
parent
fff75870
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
13 deletions
+57
-13
merge_request.rb
app/models/merge_request.rb
+17
-4
merge_request_diff.rb
app/models/merge_request_diff.rb
+3
-3
zj-memoization-mr-commits.yml
changelogs/unreleased/zj-memoization-mr-commits.yml
+5
-0
file_collection.rb
lib/gitlab/conflict/file_collection.rb
+2
-0
strong_memoize.rb
lib/gitlab/utils/strong_memoize.rb
+15
-5
strong_memoize_spec.rb
spec/lib/gitlab/utils/strong_memoize_spec.rb
+12
-0
merge_request_spec.rb
spec/models/merge_request_spec.rb
+3
-1
No files found.
app/models/merge_request.rb
View file @
1b65f905
...
@@ -8,6 +8,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -8,6 +8,7 @@ class MergeRequest < ActiveRecord::Base
include
ManualInverseAssociation
include
ManualInverseAssociation
include
EachBatch
include
EachBatch
include
ThrottledTouch
include
ThrottledTouch
include
Gitlab
::
Utils
::
StrongMemoize
ignore_column
:locked_at
,
ignore_column
:locked_at
,
:ref_fetched
:ref_fetched
...
@@ -53,6 +54,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -53,6 +54,7 @@ class MergeRequest < ActiveRecord::Base
after_create
:ensure_merge_request_diff
,
unless: :importing?
after_create
:ensure_merge_request_diff
,
unless: :importing?
after_update
:reload_diff_if_branch_changed
after_update
:reload_diff_if_branch_changed
after_update
:clear_memoized_shas
# When this attribute is true some MR validation is ignored
# When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests
# It allows us to close or modify broken merge requests
...
@@ -395,13 +397,17 @@ class MergeRequest < ActiveRecord::Base
...
@@ -395,13 +397,17 @@ class MergeRequest < ActiveRecord::Base
end
end
def
source_branch_head
def
source_branch_head
return
unless
source_project
strong_memoize
(
:source_branch_head
)
do
if
source_project
&&
source_branch_ref
source_project
.
repository
.
commit
(
source_branch_ref
)
if
source_branch_ref
source_project
.
repository
.
commit
(
source_branch_ref
)
end
end
end
end
def
target_branch_head
def
target_branch_head
target_project
.
repository
.
commit
(
target_branch_ref
)
strong_memoize
(
:target_branch_head
)
do
target_project
.
repository
.
commit
(
target_branch_ref
)
end
end
end
def
branch_merge_base_commit
def
branch_merge_base_commit
...
@@ -533,6 +539,13 @@ class MergeRequest < ActiveRecord::Base
...
@@ -533,6 +539,13 @@ class MergeRequest < ActiveRecord::Base
end
end
end
end
def
clear_memoized_shas
@target_branch_sha
=
@source_branch_sha
=
nil
clear_memoization
(
:source_branch_head
)
clear_memoization
(
:target_branch_head
)
end
def
reload_diff_if_branch_changed
def
reload_diff_if_branch_changed
if
(
source_branch_changed?
||
target_branch_changed?
)
&&
if
(
source_branch_changed?
||
target_branch_changed?
)
&&
(
source_branch_head
&&
target_branch_head
)
(
source_branch_head
&&
target_branch_head
)
...
...
app/models/merge_request_diff.rb
View file @
1b65f905
...
@@ -104,19 +104,19 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -104,19 +104,19 @@ class MergeRequestDiff < ActiveRecord::Base
def
base_commit
def
base_commit
return
unless
base_commit_sha
return
unless
base_commit_sha
project
.
commit
(
base_commit_sha
)
project
.
commit
_by
(
oid:
base_commit_sha
)
end
end
def
start_commit
def
start_commit
return
unless
start_commit_sha
return
unless
start_commit_sha
project
.
commit
(
start_commit_sha
)
project
.
commit
_by
(
oid:
start_commit_sha
)
end
end
def
head_commit
def
head_commit
return
unless
head_commit_sha
return
unless
head_commit_sha
project
.
commit
(
head_commit_sha
)
project
.
commit
_by
(
oid:
head_commit_sha
)
end
end
def
commit_shas
def
commit_shas
...
...
changelogs/unreleased/zj-memoization-mr-commits.yml
0 → 100644
View file @
1b65f905
---
title
:
Cache commits for MergeRequest diffs
merge_request
:
author
:
type
:
performance
lib/gitlab/conflict/file_collection.rb
View file @
1b65f905
...
@@ -19,6 +19,8 @@ module Gitlab
...
@@ -19,6 +19,8 @@ module Gitlab
commit_message:
commit_message
||
default_commit_message
commit_message:
commit_message
||
default_commit_message
}
}
resolver
.
resolve_conflicts
(
user
,
files
,
args
)
resolver
.
resolve_conflicts
(
user
,
files
,
args
)
ensure
@merge_request
.
clear_memoized_shas
end
end
def
files
def
files
...
...
lib/gitlab/utils/strong_memoize.rb
View file @
1b65f905
...
@@ -11,6 +11,8 @@ module Gitlab
...
@@ -11,6 +11,8 @@ module Gitlab
#
#
# We could write it like:
# We could write it like:
#
#
# include Gitlab::Utils::StrongMemoize
#
# def trigger_from_token
# def trigger_from_token
# strong_memoize(:trigger) do
# strong_memoize(:trigger) do
# Ci::Trigger.find_by_token(params[:token].to_s)
# Ci::Trigger.find_by_token(params[:token].to_s)
...
@@ -18,14 +20,22 @@ module Gitlab
...
@@ -18,14 +20,22 @@ module Gitlab
# end
# end
#
#
def
strong_memoize
(
name
)
def
strong_memoize
(
name
)
ivar_name
=
"@
#{
name
}
"
if
instance_variable_defined?
(
ivar
(
name
))
instance_variable_get
(
ivar
(
name
))
if
instance_variable_defined?
(
ivar_name
)
instance_variable_get
(
ivar_name
)
else
else
instance_variable_set
(
ivar
_name
,
yield
)
instance_variable_set
(
ivar
(
name
)
,
yield
)
end
end
end
end
def
clear_memoization
(
name
)
remove_instance_variable
(
ivar
(
name
))
if
instance_variable_defined?
(
ivar
(
name
))
end
private
def
ivar
(
name
)
"@
#{
name
}
"
end
end
end
end
end
end
end
spec/lib/gitlab/utils/strong_memoize_spec.rb
View file @
1b65f905
...
@@ -49,4 +49,16 @@ describe Gitlab::Utils::StrongMemoize do
...
@@ -49,4 +49,16 @@ describe Gitlab::Utils::StrongMemoize do
end
end
end
end
end
end
describe
'#clear_memoization'
do
let
(
:value
)
{
'mepmep'
}
it
'removes the instance variable'
do
object
.
method_name
object
.
clear_memoization
(
:method_name
)
expect
(
object
.
instance_variable_defined?
(
:@method_name
)).
to
be
(
false
)
end
end
end
end
spec/models/merge_request_spec.rb
View file @
1b65f905
...
@@ -124,6 +124,7 @@ describe MergeRequest do
...
@@ -124,6 +124,7 @@ describe MergeRequest do
context
'when the target branch does not exist'
do
context
'when the target branch does not exist'
do
before
do
before
do
project
.
repository
.
rm_branch
(
subject
.
author
,
subject
.
target_branch
)
project
.
repository
.
rm_branch
(
subject
.
author
,
subject
.
target_branch
)
subject
.
clear_memoized_shas
end
end
it
'returns nil'
do
it
'returns nil'
do
...
@@ -734,7 +735,7 @@ describe MergeRequest do
...
@@ -734,7 +735,7 @@ describe MergeRequest do
before
do
before
do
project
.
repository
.
raw_repository
.
delete_branch
(
subject
.
target_branch
)
project
.
repository
.
raw_repository
.
delete_branch
(
subject
.
target_branch
)
subject
.
reload
subject
.
clear_memoized_shas
end
end
it
'does not crash'
do
it
'does not crash'
do
...
@@ -1479,6 +1480,7 @@ describe MergeRequest do
...
@@ -1479,6 +1480,7 @@ describe MergeRequest do
context
'when the target branch does not exist'
do
context
'when the target branch does not exist'
do
before
do
before
do
subject
.
project
.
repository
.
rm_branch
(
subject
.
author
,
subject
.
target_branch
)
subject
.
project
.
repository
.
rm_branch
(
subject
.
author
,
subject
.
target_branch
)
subject
.
clear_memoized_shas
end
end
it
'returns nil'
do
it
'returns nil'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment