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
3a78e96e
Commit
3a78e96e
authored
Oct 12, 2017
by
Douwe Maan
Committed by
Lin Jen-Shin
Oct 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'cache-issuable-template-names' into 'master'
Cache issuable template names See merge request gitlab-org/gitlab-ce!14823
parent
cc411c71
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
28 deletions
+54
-28
issuables_helper.rb
app/helpers/issuables_helper.rb
+2
-10
blob.rb
app/models/blob.rb
+3
-1
repository.rb
app/models/repository.rb
+15
-2
cache-issuable-template-names.yml
changelogs/unreleased/cache-issuable-template-names.yml
+5
-0
file_detector.rb
lib/gitlab/file_detector.rb
+14
-14
file_detector_spec.rb
spec/lib/gitlab/file_detector_spec.rb
+12
-0
repository_spec.rb
spec/models/repository_spec.rb
+3
-1
No files found.
app/helpers/issuables_helper.rb
View file @
3a78e96e
...
...
@@ -314,20 +314,12 @@ module IssuablesHelper
@issuable_templates
||=
case
issuable
when
Issue
issue_template_names
ref_project
.
repository
.
issue_template_names
when
MergeRequest
merge_request_template_names
ref_project
.
repository
.
merge_request_template_names
end
end
def
merge_request_template_names
@merge_request_templates
||=
Gitlab
::
Template
::
MergeRequestTemplate
.
dropdown_names
(
ref_project
)
end
def
issue_template_names
@issue_templates
||=
Gitlab
::
Template
::
IssueTemplate
.
dropdown_names
(
ref_project
)
end
def
selected_template
(
issuable
)
params
[
:issuable_template
]
if
issuable_templates
(
issuable
).
any?
{
|
template
|
template
[
:name
]
==
params
[
:issuable_template
]
}
end
...
...
app/models/blob.rb
View file @
3a78e96e
...
...
@@ -156,7 +156,9 @@ class Blob < SimpleDelegator
end
def
file_type
Gitlab
::
FileDetector
.
type_of
(
path
)
name
=
File
.
basename
(
path
)
Gitlab
::
FileDetector
.
type_of
(
path
)
||
Gitlab
::
FileDetector
.
type_of
(
name
)
end
def
video?
...
...
app/models/repository.rb
View file @
3a78e96e
...
...
@@ -34,7 +34,8 @@ class Repository
CACHED_METHODS
=
%i(size commit_count rendered_readme contribution_guide
changelog license_blob license_key gitignore koding_yml
gitlab_ci_yml branch_names tag_names branch_count
tag_count avatar exists? empty? root_ref has_visible_content?)
.
freeze
tag_count avatar exists? empty? root_ref has_visible_content?
issue_template_names merge_request_template_names)
.
freeze
# Methods that use cache_method but only memoize the value
MEMOIZED_CACHED_METHODS
=
%i(license empty_repo?)
.
freeze
...
...
@@ -50,7 +51,9 @@ class Repository
gitignore: :gitignore
,
koding: :koding_yml
,
gitlab_ci: :gitlab_ci_yml
,
avatar: :avatar
avatar: :avatar
,
issue_template: :issue_template_names
,
merge_request_template: :merge_request_template_names
}.
freeze
# Wraps around the given method and caches its output in Redis and an instance
...
...
@@ -535,6 +538,16 @@ class Repository
end
cache_method
:avatar
def
issue_template_names
Gitlab
::
Template
::
IssueTemplate
.
dropdown_names
(
project
)
end
cache_method
:issue_template_names
,
fallback:
[]
def
merge_request_template_names
Gitlab
::
Template
::
MergeRequestTemplate
.
dropdown_names
(
project
)
end
cache_method
:merge_request_template_names
,
fallback:
[]
def
readme
if
readme
=
tree
(
:head
)
&
.
readme
ReadmeBlob
.
new
(
readme
,
self
)
...
...
changelogs/unreleased/cache-issuable-template-names.yml
0 → 100644
View file @
3a78e96e
---
title
:
Cache issue and MR template names in Redis
merge_request
:
author
:
type
:
other
lib/gitlab/file_detector.rb
View file @
3a78e96e
...
...
@@ -6,31 +6,33 @@ module Gitlab
module
FileDetector
PATTERNS
=
{
# Project files
readme:
/\Areadme/i
,
changelog:
/\A(changelog|history|changes|news)/i
,
license:
/\A(licen[sc]e|copying)(\.
.+|\z)
/i
,
contributing:
/\Acontributing/i
,
readme:
/\Areadme
[^\/]*\z
/i
,
changelog:
/\A(changelog|history|changes|news)
[^\/]*\z
/i
,
license:
/\A(licen[sc]e|copying)(\.
[^\/]+)?\z
/i
,
contributing:
/\Acontributing
[^\/]*\z
/i
,
version:
'version'
,
avatar:
/\Alogo\.(png|jpg|gif)\z/
,
issue_template:
/\A\.gitlab\/issue_templates\/[^\/]+\.md\z/
,
merge_request_template:
/\A\.gitlab\/merge_request_templates\/[^\/]+\.md\z/
,
# Configuration files
gitignore:
'.gitignore'
,
koding:
'.koding.yml'
,
gitlab_ci:
'.gitlab-ci.yml'
,
route_map:
'route-map.yml'
,
route_map:
'
.gitlab/
route-map.yml'
,
# Dependency files
cartfile:
/\ACartfile/
,
cartfile:
/\ACartfile
[^\/]*\z
/
,
composer_json:
'composer.json'
,
gemfile:
/\A(Gemfile|gems\.rb)\z/
,
gemfile_lock:
'Gemfile.lock'
,
gemspec:
/\.gemspec\z/
,
gemspec:
/\
A[^\/]*\
.gemspec\z/
,
godeps_json:
'Godeps.json'
,
package_json:
'package.json'
,
podfile:
'Podfile'
,
podspec_json:
/\.podspec\.json\z/
,
podspec:
/\.podspec\z/
,
requirements_txt:
/requirements\.txt\z/
,
podspec_json:
/\
A[^\/]*\
.podspec\.json\z/
,
podspec:
/\
A[^\/]*\
.podspec\z/
,
requirements_txt:
/
\A[^\/]*
requirements\.txt\z/
,
yarn_lock:
'yarn.lock'
}.
freeze
...
...
@@ -63,13 +65,11 @@ module Gitlab
# type_of('README.md') # => :readme
# type_of('VERSION') # => :version
def
self
.
type_of
(
path
)
name
=
File
.
basename
(
path
)
PATTERNS
.
each
do
|
type
,
search
|
did_match
=
if
search
.
is_a?
(
Regexp
)
name
=~
search
path
=~
search
else
name
.
casecmp
(
search
)
==
0
path
.
casecmp
(
search
)
==
0
end
return
type
if
did_match
...
...
spec/lib/gitlab/file_detector_spec.rb
View file @
3a78e96e
...
...
@@ -18,6 +18,10 @@ describe Gitlab::FileDetector do
expect
(
described_class
.
type_of
(
'README.md'
)).
to
eq
(
:readme
)
end
it
'returns nil for a README file in a directory'
do
expect
(
described_class
.
type_of
(
'foo/README.md'
)).
to
be_nil
end
it
'returns the type of a changelog file'
do
%w(CHANGELOG HISTORY CHANGES NEWS)
.
each
do
|
file
|
expect
(
described_class
.
type_of
(
file
)).
to
eq
(
:changelog
)
...
...
@@ -52,6 +56,14 @@ describe Gitlab::FileDetector do
end
end
it
'returns the type of an issue template'
do
expect
(
described_class
.
type_of
(
'.gitlab/issue_templates/foo.md'
)).
to
eq
(
:issue_template
)
end
it
'returns the type of a merge request template'
do
expect
(
described_class
.
type_of
(
'.gitlab/merge_request_templates/foo.md'
)).
to
eq
(
:merge_request_template
)
end
it
'returns nil for an unknown file'
do
expect
(
described_class
.
type_of
(
'foo.txt'
)).
to
be_nil
end
...
...
spec/models/repository_spec.rb
View file @
3a78e96e
...
...
@@ -1509,7 +1509,9 @@ describe Repository do
:gitignore
,
:koding
,
:gitlab_ci
,
:avatar
:avatar
,
:issue_template
,
:merge_request_template
])
repository
.
after_change_head
...
...
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