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
Léo-Paul Géneau
gitlab-ce
Commits
f107bc69
Commit
f107bc69
authored
Sep 20, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify by using Gitlab::SafeRequestStore
These are clear wins.
parent
45cf64c8
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
21 additions
and
60 deletions
+21
-60
app/controllers/concerns/with_performance_bar.rb
app/controllers/concerns/with_performance_bar.rb
+1
-5
app/models/concerns/cacheable_attributes.rb
app/models/concerns/cacheable_attributes.rb
+1
-5
app/models/legacy_diff_note.rb
app/models/legacy_diff_note.rb
+1
-5
app/models/project.rb
app/models/project.rb
+1
-5
lib/banzai/filter/external_issue_reference_filter.rb
lib/banzai/filter/external_issue_reference_filter.rb
+1
-3
lib/feature.rb
lib/feature.rb
+3
-7
lib/gitlab/current_settings.rb
lib/gitlab/current_settings.rb
+1
-5
lib/gitlab/diff/position.rb
lib/gitlab/diff/position.rb
+8
-12
lib/gitlab/git/wiki.rb
lib/gitlab/git/wiki.rb
+1
-5
lib/gitlab/issuables_count_for_state.rb
lib/gitlab/issuables_count_for_state.rb
+2
-7
lib/gitlab/performance_bar/peek_query_tracker.rb
lib/gitlab/performance_bar/peek_query_tracker.rb
+1
-1
No files found.
app/controllers/concerns/with_performance_bar.rb
View file @
f107bc69
...
@@ -10,11 +10,7 @@ module WithPerformanceBar
...
@@ -10,11 +10,7 @@ module WithPerformanceBar
def
peek_enabled?
def
peek_enabled?
return
false
unless
Gitlab
::
PerformanceBar
.
enabled?
(
current_user
)
return
false
unless
Gitlab
::
PerformanceBar
.
enabled?
(
current_user
)
if
RequestStore
.
active?
Gitlab
::
SafeRequestStore
.
fetch
(
:peek_enabled
)
{
cookie_or_default_value
}
RequestStore
.
fetch
(
:peek_enabled
)
{
cookie_or_default_value
}
else
cookie_or_default_value
end
end
end
private
private
...
...
app/models/concerns/cacheable_attributes.rb
View file @
f107bc69
...
@@ -27,11 +27,7 @@ module CacheableAttributes
...
@@ -27,11 +27,7 @@ module CacheableAttributes
end
end
def
cached
def
cached
if
RequestStore
.
active?
Gitlab
::
SafeRequestStore
[
:"
#{
name
}
_cached_attributes"
]
||=
retrieve_from_cache
RequestStore
[
:"
#{
name
}
_cached_attributes"
]
||=
retrieve_from_cache
else
retrieve_from_cache
end
end
end
def
retrieve_from_cache
def
retrieve_from_cache
...
...
app/models/legacy_diff_note.rb
View file @
f107bc69
...
@@ -20,11 +20,7 @@ class LegacyDiffNote < Note
...
@@ -20,11 +20,7 @@ class LegacyDiffNote < Note
end
end
def
project_repository
def
project_repository
if
RequestStore
.
active?
Gitlab
::
SafeRequestStore
.
fetch
(
"project:
#{
project_id
}
:repository"
)
{
self
.
project
.
repository
}
RequestStore
.
fetch
(
"project:
#{
project_id
}
:repository"
)
{
self
.
project
.
repository
}
else
self
.
project
.
repository
end
end
end
def
diff_file_hash
def
diff_file_hash
...
...
app/models/project.rb
View file @
f107bc69
...
@@ -2272,11 +2272,7 @@ class Project < ActiveRecord::Base
...
@@ -2272,11 +2272,7 @@ class Project < ActiveRecord::Base
end
end
end
end
if
RequestStore
.
active?
Gitlab
::
SafeRequestStore
.
fetch
(
"project-
#{
id
}
:branch-
#{
branch_name
}
:user-
#{
user
.
id
}
:branch_allows_collaboration"
)
do
RequestStore
.
fetch
(
"project-
#{
id
}
:branch-
#{
branch_name
}
:user-
#{
user
.
id
}
:branch_allows_collaboration"
)
do
check_access
.
call
end
else
check_access
.
call
check_access
.
call
end
end
end
end
...
...
lib/banzai/filter/external_issue_reference_filter.rb
View file @
f107bc69
...
@@ -97,9 +97,7 @@ module Banzai
...
@@ -97,9 +97,7 @@ module Banzai
private
private
def
external_issues_cached
(
attribute
)
def
external_issues_cached
(
attribute
)
return
project
.
public_send
(
attribute
)
unless
RequestStore
.
active?
# rubocop:disable GitlabSecurity/PublicSend
cached_attributes
=
Gitlab
::
SafeRequestStore
[
:banzai_external_issues_tracker_attributes
]
||=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
cached_attributes
=
RequestStore
[
:banzai_external_issues_tracker_attributes
]
||=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
cached_attributes
[
project
.
id
][
attribute
]
=
project
.
public_send
(
attribute
)
if
cached_attributes
[
project
.
id
][
attribute
].
nil?
# rubocop:disable GitlabSecurity/PublicSend
cached_attributes
[
project
.
id
][
attribute
]
=
project
.
public_send
(
attribute
)
if
cached_attributes
[
project
.
id
][
attribute
].
nil?
# rubocop:disable GitlabSecurity/PublicSend
cached_attributes
[
project
.
id
][
attribute
]
cached_attributes
[
project
.
id
][
attribute
]
end
end
...
...
lib/feature.rb
View file @
f107bc69
...
@@ -28,11 +28,7 @@ class Feature
...
@@ -28,11 +28,7 @@ class Feature
end
end
def
persisted_names
def
persisted_names
if
RequestStore
.
active?
Gitlab
::
SafeRequestStore
[
:flipper_persisted_names
]
||=
FlipperFeature
.
feature_names
RequestStore
[
:flipper_persisted_names
]
||=
FlipperFeature
.
feature_names
else
FlipperFeature
.
feature_names
end
end
end
def
persisted?
(
feature
)
def
persisted?
(
feature
)
...
@@ -76,8 +72,8 @@ class Feature
...
@@ -76,8 +72,8 @@ class Feature
end
end
def
flipper
def
flipper
if
RequestStore
.
active?
if
Gitlab
::
Safe
RequestStore
.
active?
RequestStore
[
:flipper
]
||=
build_flipper_instance
Gitlab
::
Safe
RequestStore
[
:flipper
]
||=
build_flipper_instance
else
else
@flipper
||=
build_flipper_instance
@flipper
||=
build_flipper_instance
end
end
...
...
lib/gitlab/current_settings.rb
View file @
f107bc69
...
@@ -2,11 +2,7 @@ module Gitlab
...
@@ -2,11 +2,7 @@ module Gitlab
module
CurrentSettings
module
CurrentSettings
class
<<
self
class
<<
self
def
current_application_settings
def
current_application_settings
if
RequestStore
.
active?
Gitlab
::
SafeRequestStore
.
fetch
(
:current_application_settings
)
{
ensure_application_settings!
}
RequestStore
.
fetch
(
:current_application_settings
)
{
ensure_application_settings!
}
else
ensure_application_settings!
end
end
end
def
fake_application_settings
(
attributes
=
{})
def
fake_application_settings
(
attributes
=
{})
...
...
lib/gitlab/diff/position.rb
View file @
f107bc69
...
@@ -101,18 +101,14 @@ module Gitlab
...
@@ -101,18 +101,14 @@ module Gitlab
return
@diff_file
if
defined?
(
@diff_file
)
return
@diff_file
if
defined?
(
@diff_file
)
@diff_file
=
begin
@diff_file
=
begin
if
RequestStore
.
active?
key
=
{
key
=
{
project_id:
repository
.
project
.
id
,
project_id:
repository
.
project
.
id
,
start_sha:
start_sha
,
start_sha:
start_sha
,
head_sha:
head_sha
,
head_sha:
head_sha
,
path:
file_path
path:
file_path
}
}
Gitlab
::
SafeRequestStore
.
fetch
(
key
)
{
find_diff_file
(
repository
)
}
RequestStore
.
fetch
(
key
)
{
find_diff_file
(
repository
)
}
else
find_diff_file
(
repository
)
end
end
end
end
end
...
...
lib/gitlab/git/wiki.rb
View file @
f107bc69
...
@@ -115,11 +115,7 @@ module Gitlab
...
@@ -115,11 +115,7 @@ module Gitlab
def
version
(
commit_id
)
def
version
(
commit_id
)
commit_find_proc
=
->
{
Gitlab
::
Git
::
Commit
.
find
(
@repository
,
commit_id
)
}
commit_find_proc
=
->
{
Gitlab
::
Git
::
Commit
.
find
(
@repository
,
commit_id
)
}
if
RequestStore
.
active?
Gitlab
::
SafeRequestStore
.
fetch
([
:wiki_version_commit
,
commit_id
])
{
commit_find_proc
.
call
}
RequestStore
.
fetch
([
:wiki_version_commit
,
commit_id
])
{
commit_find_proc
.
call
}
else
commit_find_proc
.
call
end
end
end
def
assert_type!
(
object
,
klass
)
def
assert_type!
(
object
,
klass
)
...
...
lib/gitlab/issuables_count_for_state.rb
View file @
f107bc69
module
Gitlab
module
Gitlab
# Class for counting and caching the number of issuables per state.
# Class for counting and caching the number of issuables per state.
class
IssuablesCountForState
class
IssuablesCountForState
# The name of the RequestStore cache key.
# The name of the
Gitlab::Safe
RequestStore cache key.
CACHE_KEY
=
:issuables_count_for_state
CACHE_KEY
=
:issuables_count_for_state
# The state values that can be safely casted to a Symbol.
# The state values that can be safely casted to a Symbol.
...
@@ -10,12 +10,7 @@ module Gitlab
...
@@ -10,12 +10,7 @@ module Gitlab
# finder - The finder class to use for retrieving the issuables.
# finder - The finder class to use for retrieving the issuables.
def
initialize
(
finder
)
def
initialize
(
finder
)
@finder
=
finder
@finder
=
finder
@cache
=
@cache
=
Gitlab
::
SafeRequestStore
[
CACHE_KEY
]
||=
initialize_cache
if
RequestStore
.
active?
RequestStore
[
CACHE_KEY
]
||=
initialize_cache
else
initialize_cache
end
end
end
def
for_state_or_opened
(
state
=
nil
)
def
for_state_or_opened
(
state
=
nil
)
...
...
lib/gitlab/performance_bar/peek_query_tracker.rb
View file @
f107bc69
...
@@ -23,7 +23,7 @@ module Gitlab
...
@@ -23,7 +23,7 @@ module Gitlab
end
end
subscribe
(
'sql.active_record'
)
do
|
_
,
start
,
finish
,
_
,
data
|
subscribe
(
'sql.active_record'
)
do
|
_
,
start
,
finish
,
_
,
data
|
if
RequestStore
.
active?
&&
RequestStore
.
store
[
:peek_enabled
]
if
Gitlab
::
Safe
RequestStore
.
store
[
:peek_enabled
]
# data[:cached] is only available starting from Rails 5.1.0
# data[:cached] is only available starting from Rails 5.1.0
# https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb#L113
# https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb#L113
# Before that, data[:name] was set to 'CACHE'
# Before that, data[:name] was set to 'CACHE'
...
...
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