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
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
...
@@ -14,10 +14,18 @@ module Gitlab
class
ReferenceFilter
<
HTML
::
Pipeline
::
Filter
class
ReferenceFilter
<
HTML
::
Pipeline
::
Filter
LazyReference
=
Struct
.
new
(
:klass
,
:ids
)
do
LazyReference
=
Struct
.
new
(
:klass
,
:ids
)
do
def
self
.
load
(
refs
)
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
)
ids
=
refs
.
flat_map
(
&
:ids
)
klass
.
where
(
id:
ids
)
klass
.
where
(
id:
ids
)
end
end
values
+
lazy_values
end
def
load
self
.
klass
.
where
(
id:
self
.
ids
)
end
end
end
end
...
...
lib/gitlab/markdown/reference_gatherer_filter.rb
View file @
cd2583a3
...
@@ -12,7 +12,6 @@ module Gitlab
...
@@ -12,7 +12,6 @@ module Gitlab
def
initialize
(
*
)
def
initialize
(
*
)
super
super
result
[
:lazy_references
]
||=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
result
[
:references
]
||=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
result
[
:references
]
||=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
end
end
...
@@ -41,23 +40,16 @@ module Gitlab
...
@@ -41,23 +40,16 @@ module Gitlab
references
.
each
do
|
type
,
values
|
references
.
each
do
|
type
,
values
|
Array
.
wrap
(
values
).
each
do
|
value
|
Array
.
wrap
(
values
).
each
do
|
value
|
refs
=
result
[
:references
][
type
]
<<
value
if
value
.
is_a?
(
ReferenceFilter
::
LazyReference
)
result
[
:lazy_references
]
else
result
[
:references
]
end
refs
[
type
]
<<
value
end
end
end
end
end
end
# Will load all references of one type using one query.
# Will load all references of one type using one query.
def
load_lazy_references
def
load_lazy_references
re
sult
[
:lazy_references
].
each
do
|
type
,
refs
|
re
fs
=
result
[
:references
]
values
=
ReferenceFilter
::
LazyReference
.
load
(
refs
)
refs
.
each
do
|
type
,
values
|
re
sult
[
:references
][
type
].
concat
(
values
)
re
fs
[
type
]
=
ReferenceFilter
::
LazyReference
.
load
(
values
)
end
end
end
end
...
...
lib/gitlab/reference_extractor.rb
View file @
cd2583a3
...
@@ -54,19 +54,13 @@ module Gitlab
...
@@ -54,19 +54,13 @@ module Gitlab
pipeline
=
HTML
::
Pipeline
.
new
([
filter
,
Gitlab
::
Markdown
::
ReferenceGathererFilter
],
context
)
pipeline
=
HTML
::
Pipeline
.
new
([
filter
,
Gitlab
::
Markdown
::
ReferenceGathererFilter
],
context
)
values
=
[]
values
=
@texts
.
flat_map
do
|
text
|
lazy_references
=
[]
@texts
.
each
do
|
text
|
result
=
pipeline
.
call
(
text
)
result
=
pipeline
.
call
(
text
)
values
.
concat
(
result
[
:references
][
filter_type
])
result
[
:references
][
filter_type
]
lazy_references
.
concat
(
result
[
:lazy_references
][
filter_type
])
end
end
lazy_values
=
Gitlab
::
Markdown
::
ReferenceFilter
::
LazyReference
.
load
(
lazy_references
)
Gitlab
::
Markdown
::
ReferenceFilter
::
LazyReference
.
load
(
values
)
values
.
concat
(
lazy_values
)
values
end
end
end
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