BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
df00ebde
Commit
df00ebde
authored
Aug 07, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY up caching in AbstractReferenceFilter
We had a lot of copied and pasted code, when the different elements were very small and easy to get wrong.
parent
76b80d6e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
40 deletions
+20
-40
abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+20
-40
No files found.
lib/banzai/filter/abstract_reference_filter.rb
View file @
df00ebde
...
...
@@ -54,9 +54,9 @@ module Banzai
self
.
class
.
references_in
(
*
args
,
&
block
)
end
# Implement in child class
# Example: project.merge_requests.find
def
find_object
(
project
,
id
)
# Implement in child class
# Example: project.merge_requests.find
end
# Override if the link reference pattern produces a different ID (global
...
...
@@ -65,47 +65,31 @@ module Banzai
find_object
(
project
,
id
)
end
def
find_object_cached
(
project
,
id
)
if
RequestStore
.
active?
cache
=
find_objects_cache
[
object_class
][
project
.
id
]
# Implement in child class
# Example: project_merge_request_url
def
url_for_object
(
object
,
project
)
end
get_or_set_cache
(
cache
,
id
)
{
find_object
(
project
,
id
)
}
else
def
find_object_cached
(
project
,
id
)
cached_call
(
:banzai_find_object
,
id
,
path:
[
object_class
,
project
.
id
])
do
find_object
(
project
,
id
)
end
end
def
find_object_from_link_cached
(
project
,
id
)
if
RequestStore
.
active?
cache
=
find_objects_from_link_cache
[
object_class
][
project
.
id
]
get_or_set_cache
(
cache
,
id
)
{
find_object_from_link
(
project
,
id
)
}
else
cached_call
(
:banzai_find_object_from_link
,
id
,
path:
[
object_class
,
project
.
id
])
do
find_object_from_link
(
project
,
id
)
end
end
def
project_from_ref_cached
(
ref
)
if
RequestStore
.
active?
cache
=
project_refs_cache
get_or_set_cache
(
cache
,
ref
)
{
project_from_ref
(
ref
)
}
else
cached_call
(
:banzai_project_refs
,
ref
)
do
project_from_ref
(
ref
)
end
end
def
url_for_object
(
object
,
project
)
# Implement in child class
# Example: project_merge_request_url
end
def
url_for_object_cached
(
object
,
project
)
if
RequestStore
.
active?
cache
=
url_for_object_cache
[
object_class
][
project
.
id
]
get_or_set_cache
(
cache
,
object
)
{
url_for_object
(
object
,
project
)
}
else
cached_call
(
:banzai_url_for_object
,
object
,
path:
[
object_class
,
project
.
id
])
do
url_for_object
(
object
,
project
)
end
end
...
...
@@ -324,21 +308,17 @@ module Banzai
RequestStore
[
:banzai_project_refs
]
||=
{}
end
def
find_objects_cache
RequestStore
[
:banzai_find_objects_cache
]
||=
Hash
.
new
do
|
hash
,
key
|
hash
[
key
]
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
end
end
def
cached_call
(
request_store_key
,
cache_key
,
path:
[])
if
RequestStore
.
active?
cache
=
RequestStore
[
request_store_key
]
||=
Hash
.
new
do
|
hash
,
key
|
hash
[
key
]
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
end
def
find_objects_from_link_cache
RequestStore
[
:banzai_find_objects_from_link_cache
]
||=
Hash
.
new
do
|
hash
,
key
|
hash
[
key
]
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
end
end
cache
=
cache
.
dig
(
*
path
)
if
path
.
any?
def
url_for_object_cache
RequestStore
[
:banzai_url_for_object
]
||=
Hash
.
new
do
|
hash
,
key
|
hash
[
key
]
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
get_or_set_cache
(
cache
,
cache_key
)
{
yield
}
else
yield
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