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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
671f82ed
Commit
671f82ed
authored
Jun 07, 2021
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up checking whether fields are markdown fields or not
parent
6dc033f2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
4 deletions
+11
-4
app/models/concerns/cache_markdown_field.rb
app/models/concerns/cache_markdown_field.rb
+3
-3
lib/gitlab/markdown_cache/field_data.rb
lib/gitlab/markdown_cache/field_data.rb
+1
-1
spec/lib/gitlab/markdown_cache/field_data_spec.rb
spec/lib/gitlab/markdown_cache/field_data_spec.rb
+7
-0
No files found.
app/models/concerns/cache_markdown_field.rb
View file @
671f82ed
...
...
@@ -27,7 +27,7 @@ module CacheMarkdownField
# Returns the default Banzai render context for the cached markdown field.
def
banzai_render_context
(
field
)
raise
ArgumentError
,
"Unknown field:
#{
field
.
inspect
}
"
unless
cached_markdown_fields
.
markdown_fields
.
include
?
(
field
)
cached_markdown_fields
.
key
?
(
field
)
# Always include a project key, or Banzai complains
project
=
self
.
project
if
self
.
respond_to?
(
:project
)
...
...
@@ -100,7 +100,7 @@ module CacheMarkdownField
def
cached_html_for
(
markdown_field
)
raise
ArgumentError
,
"Unknown field:
#{
markdown_field
}
"
unless
cached_markdown_fields
.
markdown_fields
.
include
?
(
markdown_field
)
cached_markdown_fields
.
key
?
(
markdown_field
)
__send__
(
cached_markdown_fields
.
html_field
(
markdown_field
))
# rubocop:disable GitlabSecurity/PublicSend
end
...
...
@@ -108,7 +108,7 @@ module CacheMarkdownField
# Updates the markdown cache if necessary, then returns the field
# Unlike `cached_html_for` it returns `nil` if the field does not exist
def
updated_cached_html_for
(
markdown_field
)
return
unless
cached_markdown_fields
.
markdown_fields
.
include
?
(
markdown_field
)
return
unless
cached_markdown_fields
.
key
?
(
markdown_field
)
if
attribute_invalidated?
(
cached_markdown_fields
.
html_field
(
markdown_field
))
# Invalidated due to Markdown content change
...
...
lib/gitlab/markdown_cache/field_data.rb
View file @
671f82ed
...
...
@@ -9,7 +9,7 @@ module Gitlab
@data
=
{}
end
delegate
:[]
,
:[]=
,
to: :@data
delegate
:[]
,
:[]=
,
:key?
,
to: :@data
def
markdown_fields
@data
.
keys
...
...
spec/lib/gitlab/markdown_cache/field_data_spec.rb
View file @
671f82ed
...
...
@@ -12,4 +12,11 @@ RSpec.describe Gitlab::MarkdownCache::FieldData do
it
'translates a markdown field name into a html field name'
do
expect
(
field_data
.
html_field
(
:description
)).
to
eq
(
"description_html"
)
end
describe
'#key?'
do
specify
do
expect
(
field_data
.
key?
(
:description
)).
to
be_truthy
expect
(
field_data
.
key?
(
:something_else
)).
to
be_falsy
end
end
end
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