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
76f8c168
Commit
76f8c168
authored
Jul 13, 2020
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce 'cached' calls for Banzai
- Fix Snippet parser - Fix Label Reference filter
parent
31a1c997
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
4 deletions
+24
-4
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+7
-1
lib/banzai/reference_parser/base_parser.rb
lib/banzai/reference_parser/base_parser.rb
+2
-1
lib/banzai/reference_parser/snippet_parser.rb
lib/banzai/reference_parser/snippet_parser.rb
+15
-2
No files found.
lib/banzai/filter/label_reference_filter.rb
View file @
76f8c168
...
...
@@ -19,7 +19,7 @@ module Banzai
unescaped_html
=
unescape_html_entities
(
text
).
gsub
(
pattern
)
do
|
match
|
namespace
,
project
=
$~
[
:namespace
],
$~
[
:project
]
project_path
=
full_project_path
(
namespace
,
project
)
label
=
find_label
(
project_path
,
$~
[
:label_id
],
$~
[
:label_name
])
label
=
find_label
_cached
(
project_path
,
$~
[
:label_id
],
$~
[
:label_name
])
if
label
labels
[
label
.
id
]
=
yield
match
,
label
.
id
,
project
,
namespace
,
$~
...
...
@@ -34,6 +34,12 @@ module Banzai
escape_with_placeholders
(
unescaped_html
,
labels
)
end
def
find_label_cached
(
parent_ref
,
label_id
,
label_name
)
cached_call
(
:banzai_find_label_cached
,
label_name
&
.
tr
(
'"'
,
''
)
||
label_id
,
path:
[
object_class
,
parent_ref
])
do
find_label
(
parent_ref
,
label_id
,
label_name
)
end
end
def
find_label
(
parent_ref
,
label_id
,
label_name
)
parent
=
parent_from_ref
(
parent_ref
)
return
unless
parent
...
...
lib/banzai/reference_parser/base_parser.rb
View file @
76f8c168
...
...
@@ -169,7 +169,8 @@ module Banzai
# been queried the object is returned from the cache.
def
collection_objects_for_ids
(
collection
,
ids
)
if
Gitlab
::
SafeRequestStore
.
active?
ids
=
ids
.
map
(
&
:to_i
)
ids
=
ids
.
map
(
&
:to_i
).
uniq
cache
=
collection_cache
[
collection_cache_key
(
collection
)]
to_query
=
ids
-
cache
.
keys
...
...
lib/banzai/reference_parser/snippet_parser.rb
View file @
76f8c168
...
...
@@ -9,10 +9,23 @@ module Banzai
Snippet
end
# Returns all the nodes that are visible to the given user.
def
nodes_visible_to_user
(
user
,
nodes
)
snippets
=
lazy
{
grouped_objects_for_nodes
(
nodes
,
references_relation
,
self
.
class
.
data_attribute
)
}
nodes
.
select
do
|
node
|
if
node
.
has_attribute?
(
self
.
class
.
data_attribute
)
can_read_reference?
(
user
,
snippets
[
node
])
else
true
end
end
end
private
def
can_read_reference?
(
user
,
ref_project
,
node
)
can?
(
user
,
:read_snippet
,
referenced_by
([
node
]).
firs
t
)
def
can_read_reference?
(
user
,
snippet
)
can?
(
user
,
:read_snippet
,
snippe
t
)
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