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
9b0e131b
Commit
9b0e131b
authored
Jul 29, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'cache-commit-author-lookup' into 'master'
Cache the commit author in RequestStore to avoid extra lookups in PostReceive See merge request !5537
parents
5161983b
d27e36f3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
1 deletion
+37
-1
CHANGELOG
CHANGELOG
+1
-0
commit.rb
app/models/commit.rb
+16
-1
commit_spec.rb
spec/models/commit_spec.rb
+20
-0
No files found.
CHANGELOG
View file @
9b0e131b
...
...
@@ -4,6 +4,7 @@ v 8.11.0 (unreleased)
- Fix the title of the toggle dropdown button. !5515 (herminiotorres)
- Remove magic comments (`# encoding: UTF-8`) from Ruby files. !5456 (winniehell)
- Fix CI status icon link underline (ClemMakesApps)
- Cache the commit author in RequestStore to avoid extra lookups in PostReceive
- Fix of 'Commits being passed to custom hooks are already reachable when using the UI'
- Add support for using RequestStore within Sidekiq tasks via SIDEKIQ_REQUEST_STORE env variable
- Optimize maximum user access level lookup in loading of notes
...
...
app/models/commit.rb
View file @
9b0e131b
...
...
@@ -178,7 +178,18 @@ class Commit
end
def
author
@author
||=
User
.
find_by_any_email
(
author_email
.
downcase
)
if
RequestStore
.
active?
key
=
"commit_author:
#{
author_email
.
downcase
}
"
# nil is a valid value since no author may exist in the system
if
RequestStore
.
store
.
has_key?
(
key
)
@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
def
committer
...
...
@@ -306,6 +317,10 @@ class Commit
private
def
find_author_by_any_email
User
.
find_by_any_email
(
author_email
.
downcase
)
end
def
repo_changes
changes
=
{
added:
[],
modified:
[],
removed:
[]
}
...
...
spec/models/commit_spec.rb
View file @
9b0e131b
...
...
@@ -13,6 +13,26 @@ describe Commit, models: true do
it
{
is_expected
.
to
include_module
(
StaticModel
)
}
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
it
'returns a String reference to the object'
do
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