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
f5f2644d
Commit
f5f2644d
authored
Aug 30, 2021
by
Gary Holtz
Committed by
Andy Soiron
Aug 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Caching the protected branch check
Changelog: performance
parent
1f1e125f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
app/models/protected_branch.rb
app/models/protected_branch.rb
+3
-1
spec/models/protected_branch_spec.rb
spec/models/protected_branch_spec.rb
+24
-0
No files found.
app/models/protected_branch.rb
View file @
f5f2644d
...
@@ -26,7 +26,9 @@ class ProtectedBranch < ApplicationRecord
...
@@ -26,7 +26,9 @@ class ProtectedBranch < ApplicationRecord
def
self
.
protected?
(
project
,
ref_name
)
def
self
.
protected?
(
project
,
ref_name
)
return
true
if
project
.
empty_repo?
&&
project
.
default_branch_protected?
return
true
if
project
.
empty_repo?
&&
project
.
default_branch_protected?
self
.
matching
(
ref_name
,
protected_refs:
protected_refs
(
project
)).
present?
Rails
.
cache
.
fetch
(
"protected_ref-
#{
ref_name
}
-
#{
project
.
cache_key
}
"
)
do
self
.
matching
(
ref_name
,
protected_refs:
protected_refs
(
project
)).
present?
end
end
end
def
self
.
allow_force_push?
(
project
,
ref_name
)
def
self
.
allow_force_push?
(
project
,
ref_name
)
...
...
spec/models/protected_branch_spec.rb
View file @
f5f2644d
...
@@ -162,6 +162,30 @@ RSpec.describe ProtectedBranch do
...
@@ -162,6 +162,30 @@ RSpec.describe ProtectedBranch do
expect
(
described_class
.
protected?
(
project
,
'staging/some-branch'
)).
to
eq
(
false
)
expect
(
described_class
.
protected?
(
project
,
'staging/some-branch'
)).
to
eq
(
false
)
end
end
context
'with caching'
,
:use_clean_rails_memory_store_caching
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:protected_branch
)
{
create
(
:protected_branch
,
project:
project
,
name:
"jawn"
)
}
before
do
allow
(
described_class
).
to
receive
(
:matching
).
once
.
and_call_original
# the original call works and warms the cache
described_class
.
protected?
(
project
,
'jawn'
)
end
it
'correctly invalidates a cache'
do
expect
(
described_class
).
to
receive
(
:matching
).
once
.
and_call_original
create
(
:protected_branch
,
project:
project
,
name:
"bar"
)
# the cache is invalidated because the project has been "updated"
expect
(
described_class
.
protected?
(
project
,
'jawn'
)).
to
eq
(
true
)
end
it
'correctly uses the cached version'
do
expect
(
described_class
).
not_to
receive
(
:matching
)
expect
(
described_class
.
protected?
(
project
,
'jawn'
)).
to
eq
(
true
)
end
end
end
end
context
'new project'
do
context
'new project'
do
...
...
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