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
Boxiang Sun
gitlab-ce
Commits
e893f560
Commit
e893f560
authored
Dec 28, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary double caching (in hash and request store)
parent
7388a911
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
21 deletions
+4
-21
app/models/project.rb
app/models/project.rb
+3
-13
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-7
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+1
-1
No files found.
app/models/project.rb
View file @
e893f560
...
...
@@ -1932,23 +1932,11 @@ class Project < ActiveRecord::Base
end
def
any_branch_allows_collaboration?
(
user
)
return
false
unless
user
fetch_branch_allows_collaboration
(
user
)
end
def
branch_allows_collaboration?
(
user
,
branch_name
)
return
false
unless
user
cache_key
=
"user:
#{
user
.
id
}
:
#{
branch_name
}
:branch_allows_push"
memoized_results
=
strong_memoize
(
:branch_allows_collaboration
)
do
Hash
.
new
do
|
result
,
cache_key
|
result
[
cache_key
]
=
fetch_branch_allows_collaboration
(
user
,
branch_name
)
end
end
memoized_results
[
cache_key
]
fetch_branch_allows_collaboration
(
user
,
branch_name
)
end
def
licensed_features
...
...
@@ -2153,6 +2141,8 @@ class Project < ActiveRecord::Base
end
def
fetch_branch_allows_collaboration
(
user
,
branch_name
=
nil
)
return
false
unless
user
Gitlab
::
SafeRequestStore
.
fetch
(
"project-
#{
id
}
:branch-
#{
branch_name
}
:user-
#{
user
.
id
}
:branch_allows_collaboration"
)
do
next
false
if
empty_repo?
...
...
spec/models/project_spec.rb
View file @
e893f560
...
...
@@ -3932,13 +3932,6 @@ describe Project do
.
to
be_falsy
end
it
'caches the result'
do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
project
.
branch_allows_collaboration?
(
user
,
'awesome-feature-1'
)
}
expect
{
3
.
times
{
project
.
branch_allows_collaboration?
(
user
,
'awesome-feature-1'
)
}
}
.
not_to
exceed_query_limit
(
control
)
end
context
'when the requeststore is active'
,
:request_store
do
it
'only queries per project across instances'
do
control
=
ActiveRecord
::
QueryRecorder
.
new
{
project
.
branch_allows_collaboration?
(
user
,
'awesome-feature-1'
)
}
...
...
spec/serializers/pipeline_serializer_spec.rb
View file @
e893f560
...
...
@@ -144,7 +144,7 @@ describe PipelineSerializer do
# pipeline. With the same ref this check is cached but if refs are
# different then there is an extra query per ref
# https://gitlab.com/gitlab-org/gitlab-ce/issues/46368
expect
(
recorded
.
count
).
to
be_within
(
2
).
of
(
3
4
)
expect
(
recorded
.
count
).
to
be_within
(
2
).
of
(
3
8
)
expect
(
recorded
.
cached_count
).
to
eq
(
0
)
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