Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
d27e36f3
Commit
d27e36f3
authored
Jul 27, 2016
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for caching commit author
parent
8a9fc2b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
app/models/commit.rb
app/models/commit.rb
+15
-7
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+20
-0
No files found.
app/models/commit.rb
View file @
d27e36f3
...
@@ -178,14 +178,18 @@ class Commit
...
@@ -178,14 +178,18 @@ class Commit
end
end
def
author
def
author
key
=
"commit_author:
#{
author_email
}
"
if
RequestStore
.
active?
key
=
"commit_author:
#{
author_email
.
downcase
}
"
# nil is a valid value since no author may exist in the system
# nil is a valid value since no author may exist in the system
unless
RequestStore
.
store
.
has_key?
(
key
)
if
RequestStore
.
store
.
has_key?
(
key
)
RequestStore
.
store
[
key
]
=
User
.
find_by_any_email
(
author_email
.
downcase
)
@author
=
RequestStore
.
store
[
key
]
else
@author
=
find_author_by_any_email
RequestStore
.
store
[
key
]
=
@author
end
else
@author
||=
find_author_by_any_email
end
end
@author
||=
RequestStore
.
store
[
key
]
end
end
def
committer
def
committer
...
@@ -313,6 +317,10 @@ class Commit
...
@@ -313,6 +317,10 @@ class Commit
private
private
def
find_author_by_any_email
User
.
find_by_any_email
(
author_email
.
downcase
)
end
def
repo_changes
def
repo_changes
changes
=
{
added:
[],
modified:
[],
removed:
[]
}
changes
=
{
added:
[],
modified:
[],
removed:
[]
}
...
...
spec/models/commit_spec.rb
View file @
d27e36f3
...
@@ -13,6 +13,26 @@ describe Commit, models: true do
...
@@ -13,6 +13,26 @@ describe Commit, models: true do
it
{
is_expected
.
to
include_module
(
StaticModel
)
}
it
{
is_expected
.
to
include_module
(
StaticModel
)
}
end
end
describe
'#author'
do
it
'looks up the author in a case-insensitive way'
do
user
=
create
(
:user
,
email:
commit
.
author_email
.
upcase
)
expect
(
commit
.
author
).
to
eq
(
user
)
end
it
'caches the author'
do
user
=
create
(
:user
,
email:
commit
.
author_email
)
expect
(
RequestStore
).
to
receive
(
:active?
).
twice
.
and_return
(
true
)
expect_any_instance_of
(
Commit
).
to
receive
(
:find_author_by_any_email
).
and_call_original
expect
(
commit
.
author
).
to
eq
(
user
)
key
=
"commit_author:
#{
commit
.
author_email
}
"
expect
(
RequestStore
.
store
[
key
]).
to
eq
(
user
)
expect
(
commit
.
author
).
to
eq
(
user
)
RequestStore
.
store
.
clear
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
commit
.
to_reference
).
to
eq
commit
.
id
expect
(
commit
.
to_reference
).
to
eq
commit
.
id
...
...
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