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
49fcbe5e
Commit
49fcbe5e
authored
Jan 05, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly memoize ChangeAccess#validate_path_locks? to avoid excessive queries
Closes #4488
parent
d9014ba8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
changelogs/unreleased-ee/sh-strong-memoize-validate-path-locks.yml
...s/unreleased-ee/sh-strong-memoize-validate-path-locks.yml
+5
-0
lib/gitlab/checks/change_access.rb
lib/gitlab/checks/change_access.rb
+6
-3
spec/lib/gitlab/checks/change_access_spec.rb
spec/lib/gitlab/checks/change_access_spec.rb
+6
-0
No files found.
changelogs/unreleased-ee/sh-strong-memoize-validate-path-locks.yml
0 → 100644
View file @
49fcbe5e
---
title
:
Properly memoize ChangeAccess#validate_path_locks? to avoid excessive queries
merge_request
:
author
:
type
:
performance
lib/gitlab/checks/change_access.rb
View file @
49fcbe5e
...
...
@@ -2,6 +2,7 @@ module Gitlab
module
Checks
class
ChangeAccess
include
PathLocksHelper
include
Gitlab
::
Utils
::
StrongMemoize
ERROR_MESSAGES
=
{
push_code:
'You are not allowed to push code to this project.'
,
...
...
@@ -300,9 +301,11 @@ module Gitlab
end
def
validate_path_locks?
@validate_path_locks
||=
@project
.
feature_available?
(
:file_locks
)
&&
project
.
path_locks
.
any?
&&
@newrev
&&
@oldrev
&&
project
.
default_branch
==
@branch_name
# locks protect default branch only
strong_memoize
(
:validate_path_locks
)
do
@project
.
feature_available?
(
:file_locks
)
&&
project
.
path_locks
.
any?
&&
@newrev
&&
@oldrev
&&
project
.
default_branch
==
@branch_name
# locks protect default branch only
end
end
def
path_locks_validation
...
...
spec/lib/gitlab/checks/change_access_spec.rb
View file @
49fcbe5e
...
...
@@ -319,6 +319,12 @@ describe Gitlab::Checks::ChangeAccess do
it
'allows the default branch even if it does not match push rule'
do
expect
{
subject
.
exec
}.
not_to
raise_error
end
it
'memoizes the validate_path_locks? call'
do
expect
(
project
.
path_locks
).
to
receive
(
:any?
).
once
.
and_call_original
2
.
times
{
subject
.
exec
}
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