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
cd2583a3
Commit
cd2583a3
authored
Oct 13, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup
parent
93fcddd7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
23 deletions
+17
-23
lib/gitlab/markdown/reference_filter.rb
lib/gitlab/markdown/reference_filter.rb
+9
-1
lib/gitlab/markdown/reference_gatherer_filter.rb
lib/gitlab/markdown/reference_gatherer_filter.rb
+5
-13
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+3
-9
No files found.
lib/gitlab/markdown/reference_filter.rb
View file @
cd2583a3
...
...
@@ -14,10 +14,18 @@ module Gitlab
class
ReferenceFilter
<
HTML
::
Pipeline
::
Filter
LazyReference
=
Struct
.
new
(
:klass
,
:ids
)
do
def
self
.
load
(
refs
)
refs
.
group_by
(
&
:klass
).
flat_map
do
|
klass
,
refs
|
lazy_references
,
values
=
refs
.
partition
{
|
ref
|
ref
.
is_a?
(
self
)
}
lazy_values
=
lazy_references
.
group_by
(
&
:klass
).
flat_map
do
|
klass
,
refs
|
ids
=
refs
.
flat_map
(
&
:ids
)
klass
.
where
(
id:
ids
)
end
values
+
lazy_values
end
def
load
self
.
klass
.
where
(
id:
self
.
ids
)
end
end
...
...
lib/gitlab/markdown/reference_gatherer_filter.rb
View file @
cd2583a3
...
...
@@ -12,7 +12,6 @@ module Gitlab
def
initialize
(
*
)
super
result
[
:lazy_references
]
||=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
result
[
:references
]
||=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
end
...
...
@@ -41,23 +40,16 @@ module Gitlab
references
.
each
do
|
type
,
values
|
Array
.
wrap
(
values
).
each
do
|
value
|
refs
=
if
value
.
is_a?
(
ReferenceFilter
::
LazyReference
)
result
[
:lazy_references
]
else
result
[
:references
]
end
refs
[
type
]
<<
value
result
[
:references
][
type
]
<<
value
end
end
end
# Will load all references of one type using one query.
def
load_lazy_references
re
sult
[
:lazy_references
].
each
do
|
type
,
refs
|
values
=
ReferenceFilter
::
LazyReference
.
load
(
refs
)
re
sult
[
:references
][
type
].
concat
(
values
)
re
fs
=
result
[
:references
]
refs
.
each
do
|
type
,
values
|
re
fs
[
type
]
=
ReferenceFilter
::
LazyReference
.
load
(
values
)
end
end
...
...
lib/gitlab/reference_extractor.rb
View file @
cd2583a3
...
...
@@ -54,19 +54,13 @@ module Gitlab
pipeline
=
HTML
::
Pipeline
.
new
([
filter
,
Gitlab
::
Markdown
::
ReferenceGathererFilter
],
context
)
values
=
[]
lazy_references
=
[]
@texts
.
each
do
|
text
|
values
=
@texts
.
flat_map
do
|
text
|
result
=
pipeline
.
call
(
text
)
values
.
concat
(
result
[
:references
][
filter_type
])
lazy_references
.
concat
(
result
[
:lazy_references
][
filter_type
])
result
[
:references
][
filter_type
]
end
lazy_values
=
Gitlab
::
Markdown
::
ReferenceFilter
::
LazyReference
.
load
(
lazy_references
)
values
.
concat
(
lazy_values
)
values
Gitlab
::
Markdown
::
ReferenceFilter
::
LazyReference
.
load
(
values
)
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