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
iv
gitlab-ce
Commits
da9746e5
Commit
da9746e5
authored
Oct 14, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable caching of Gitlab::Markdown rendered result
parent
ed41333a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
12 deletions
+27
-12
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+25
-10
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+2
-2
No files found.
lib/gitlab/markdown.rb
View file @
da9746e5
...
@@ -20,14 +20,16 @@ module Gitlab
...
@@ -20,14 +20,16 @@ module Gitlab
#
#
# Returns an HTML-safe String
# Returns an HTML-safe String
def
self
.
render
(
text
,
context
=
{})
def
self
.
render
(
text
,
context
=
{})
pipeline
=
context
[
:pipeline
]
||
:full
cache_key
=
context
.
delete
(
:cache_key
)
html_pipeline
=
html_pipelines
[
pipeline
]
transformers
=
get_context_transformers
(
pipeline
)
context
=
transformers
.
reduce
(
context
)
{
|
context
,
transformer
|
transformer
.
call
(
context
)
}
html_pipeline
.
to_html
(
text
,
context
)
if
cache_key
cache_key
=
full_cache_key
(
cache_key
,
context
[
:pipeline
])
Rails
.
cache
.
fetch
(
cache_key
)
do
cacheless_render
(
text
,
context
)
end
else
cacheless_render
(
text
,
context
)
end
end
end
# Provide autoload paths for filters to prevent a circular dependency error
# Provide autoload paths for filters to prevent a circular dependency error
...
@@ -130,9 +132,7 @@ module Gitlab
...
@@ -130,9 +132,7 @@ module Gitlab
],
],
email:
[
email:
[
:full
,
:full
,
{
{
only_path:
false
}
only_path:
false
}
],
],
description:
[
description:
[
:full
,
:full
,
...
@@ -155,6 +155,17 @@ module Gitlab
...
@@ -155,6 +155,17 @@ module Gitlab
end
end
end
end
def
self
.
cacheless_render
(
text
,
context
=
{})
pipeline
=
context
[
:pipeline
]
||
:full
html_pipeline
=
html_pipelines
[
pipeline
]
transformers
=
get_context_transformers
(
pipeline
)
context
=
transformers
.
reduce
(
context
)
{
|
context
,
transformer
|
transformer
.
call
(
context
)
}
html_pipeline
.
to_html
(
text
,
context
)
end
def
self
.
get_filters
(
pipelines
)
def
self
.
get_filters
(
pipelines
)
Array
.
wrap
(
pipelines
).
flat_map
do
|
pipeline
|
Array
.
wrap
(
pipelines
).
flat_map
do
|
pipeline
|
case
pipeline
case
pipeline
...
@@ -182,5 +193,9 @@ module Gitlab
...
@@ -182,5 +193,9 @@ module Gitlab
end
end
end
.
compact
end
.
compact
end
end
def
self
.
full_cache_key
(
cache_key
,
pipeline
=
:full
)
[
"markdown"
,
*
cache_key
,
pipeline
]
end
end
end
end
end
lib/gitlab/reference_extractor.rb
View file @
da9746e5
...
@@ -11,10 +11,10 @@ module Gitlab
...
@@ -11,10 +11,10 @@ module Gitlab
@load_lazy_references
=
load_lazy_references
@load_lazy_references
=
load_lazy_references
end
end
def
analyze
(
text
)
def
analyze
(
text
,
cache_key:
nil
)
references
.
clear
references
.
clear
@document
=
Gitlab
::
Markdown
.
render
(
text
,
project:
project
)
@document
=
Gitlab
::
Markdown
.
render
(
text
,
project:
project
,
cache_key:
cache_key
)
end
end
%i(user label issue merge_request snippet commit commit_range)
.
each
do
|
type
|
%i(user label issue merge_request snippet commit commit_range)
.
each
do
|
type
|
...
...
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