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
5be0daca
Commit
5be0daca
authored
Feb 03, 2020
by
Robert May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Rails' serialisation instead of JSON
parent
6bfecb09
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
13 deletions
+17
-13
app/models/repository.rb
app/models/repository.rb
+7
-5
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+10
-8
No files found.
app/models/repository.rb
View file @
5be0daca
...
...
@@ -65,6 +65,8 @@ class Repository
xcode_config: :xcode_project?
}.
freeze
MERGED_BRANCH_NAMES_CACHE_DURATION
=
10
.
minutes
def
initialize
(
full_path
,
project
,
disk_path:
nil
,
repo_type:
Gitlab
::
GlRepository
::
PROJECT
)
@full_path
=
full_path
@disk_path
=
disk_path
||
full_path
...
...
@@ -923,7 +925,7 @@ class Repository
return
raw_repository
.
merged_branch_names
(
branch_names
)
if
skip_cache
cached_branch_names
=
cache
.
read
(
:merged_branch_names
)
merged_branch_names_hash
=
cached_branch_names
.
present?
?
JSON
.
parse
(
cached_branch_names
)
:
{}
merged_branch_names_hash
=
cached_branch_names
||
{}
missing_branch_names
=
branch_names
.
select
{
|
bn
|
!
merged_branch_names_hash
.
key?
(
bn
)
}
# Track some metrics here whilst feature flag is enabled
...
...
@@ -935,17 +937,17 @@ class Repository
counter
.
increment
(
full_hit:
missing_branch_names
.
empty?
)
end
unless
missing_branch_names
.
empt
y?
if
missing_branch_names
.
an
y?
merged
=
raw_repository
.
merged_branch_names
(
missing_branch_names
)
missing_branch_names
.
each
do
|
bn
|
merged_branch_names_hash
[
bn
]
=
merged
.
include?
(
bn
)
.
to_s
merged_branch_names_hash
[
bn
]
=
merged
.
include?
(
bn
)
end
cache
.
write
(
:merged_branch_names
,
merged_branch_names_hash
.
to_json
,
expires_in:
10
.
minutes
)
cache
.
write
(
:merged_branch_names
,
merged_branch_names_hash
,
expires_in:
MERGED_BRANCH_NAMES_CACHE_DURATION
)
end
Set
.
new
(
merged_branch_names_hash
.
select
{
|
k
,
v
|
v
.
to_s
==
"true"
}.
keys
)
Set
.
new
(
merged_branch_names_hash
.
select
{
|
_
,
v
|
v
}.
keys
)
end
def
merge_base
(
*
commits_or_ids
)
...
...
spec/models/repository_spec.rb
View file @
5be0daca
...
...
@@ -502,10 +502,10 @@ describe Repository do
let
(
:merge_state_hash
)
do
{
"test"
=>
"false"
,
"beep"
=>
"false"
,
"boop"
=>
"false"
,
"definitely_merged"
=>
"true"
"test"
=>
false
,
"beep"
=>
false
,
"boop"
=>
false
,
"definitely_merged"
=>
true
}
end
...
...
@@ -538,7 +538,7 @@ describe Repository do
describe
"cache values"
do
it
"writes the values to redis"
do
expect
(
cache
).
to
receive
(
:write
).
with
(
cache_key
,
merge_state_hash
.
to_json
,
expires_in:
10
.
minutes
)
expect
(
cache
).
to
receive
(
:write
).
with
(
cache_key
,
merge_state_hash
,
expires_in:
Repository
::
MERGED_BRANCH_NAMES_CACHE_DURATION
)
subject
end
...
...
@@ -546,20 +546,21 @@ describe Repository do
it
"matches the supplied hash"
do
subject
expect
(
JSON
.
parse
(
cache
.
read
(
cache_key
)
)).
to
eq
(
merge_state_hash
)
expect
(
cache
.
read
(
cache_key
)).
to
eq
(
merge_state_hash
)
end
end
end
context
"cache is not empty"
do
before
do
cache
.
write
(
cache_key
,
merge_state_hash
.
to_json
)
cache
.
write
(
cache_key
,
merge_state_hash
)
end
it
{
is_expected
.
to
eq
(
already_merged
)
}
it
"doesn't fetch from the disk"
do
expect
(
repository
.
raw_repository
).
not_to
receive
(
:merged_branch_names
)
subject
end
end
...
...
@@ -568,13 +569,14 @@ describe Repository do
before
do
allow
(
repository
.
raw_repository
).
to
receive
(
:merged_branch_names
).
with
([
"boop"
]).
and_return
([])
hash
=
merge_state_hash
.
except
(
"boop"
)
cache
.
write
(
cache_key
,
hash
.
to_json
)
cache
.
write
(
cache_key
,
hash
)
end
it
{
is_expected
.
to
eq
(
already_merged
)
}
it
"does fetch from the disk"
do
expect
(
repository
.
raw_repository
).
to
receive
(
:merged_branch_names
).
with
([
"boop"
])
subject
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