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
ae11d316
Commit
ae11d316
authored
3 years ago
by
Matija Čupić
Committed by
Michael Kozono
3 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create finder for searching branch names via redis
parent
ae271da6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
0 deletions
+101
-0
app/finders/repositories/branch_names_finder.rb
app/finders/repositories/branch_names_finder.rb
+24
-0
app/models/repository.rb
app/models/repository.rb
+4
-0
changelogs/unreleased/mc-backstage-use-redis-in-branch-finder.yml
...gs/unreleased/mc-backstage-use-redis-in-branch-finder.yml
+5
-0
lib/gitlab/repository_set_cache.rb
lib/gitlab/repository_set_cache.rb
+15
-0
spec/finders/repositories/branch_names_finder_spec.rb
spec/finders/repositories/branch_names_finder_spec.rb
+25
-0
spec/lib/gitlab/repository_set_cache_spec.rb
spec/lib/gitlab/repository_set_cache_spec.rb
+12
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+16
-0
No files found.
app/finders/repositories/branch_names_finder.rb
0 → 100644
View file @
ae11d316
# frozen_string_literal: true
module
Repositories
class
BranchNamesFinder
attr_reader
:repository
,
:params
def
initialize
(
repository
,
params
=
{})
@repository
=
repository
@params
=
params
end
def
execute
return
unless
search
repository
.
search_branch_names
(
search
)
end
private
def
search
@params
[
:search
].
presence
end
end
end
This diff is collapsed.
Click to expand it.
app/models/repository.rb
View file @
ae11d316
...
...
@@ -288,6 +288,10 @@ class Repository
false
end
def
search_branch_names
(
pattern
)
redis_set_cache
.
search
(
'branch_names'
,
pattern
)
{
branch_names
}
end
def
languages
return
[]
if
empty?
...
...
This diff is collapsed.
Click to expand it.
changelogs/unreleased/mc-backstage-use-redis-in-branch-finder.yml
0 → 100644
View file @
ae11d316
---
title
:
Create finder for searching branch names via redis.
merge_request
:
58439
author
:
type
:
performance
This diff is collapsed.
Click to expand it.
lib/gitlab/repository_set_cache.rb
View file @
ae11d316
...
...
@@ -49,5 +49,20 @@ module Gitlab
write
(
key
,
yield
)
end
# Searches the cache set using SSCAN with the MATCH option. The MATCH
# parameter is the pattern argument.
# See https://redis.io/commands/scan#the-match-option for more information.
# Returns an Enumerator that enumerates all SSCAN hits.
def
search
(
key
,
pattern
,
&
block
)
full_key
=
cache_key
(
key
)
with
do
|
redis
|
exists
=
redis
.
exists
(
full_key
)
write
(
key
,
yield
)
unless
exists
redis
.
sscan_each
(
full_key
,
match:
pattern
)
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/finders/repositories/branch_names_finder_spec.rb
0 → 100644
View file @
ae11d316
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Repositories
::
BranchNamesFinder
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:branch_names_finder
)
{
described_class
.
new
(
project
.
repository
,
search:
'conflict-*'
)
}
describe
'#execute'
do
subject
(
:execute
)
{
branch_names_finder
.
execute
}
it
'filters branch names'
do
expect
(
execute
).
to
contain_exactly
(
'conflict-binary-file'
,
'conflict-resolvable'
,
'conflict-contains-conflict-markers'
,
'conflict-missing-side'
,
'conflict-start'
,
'conflict-non-utf8'
,
'conflict-too-large'
)
end
end
end
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/repository_set_cache_spec.rb
View file @
ae11d316
...
...
@@ -124,6 +124,18 @@ RSpec.describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
end
end
describe
'#search'
do
subject
do
cache
.
search
(
:foo
,
'val*'
)
do
%w[value helloworld notvalmatch]
end
end
it
'returns search pattern matches from the key'
do
is_expected
.
to
contain_exactly
(
'value'
)
end
end
describe
'#include?'
do
it
'checks inclusion in the Redis set'
do
cache
.
write
(
:foo
,
[
'value'
])
...
...
This diff is collapsed.
Click to expand it.
spec/models/repository_spec.rb
View file @
ae11d316
...
...
@@ -170,6 +170,22 @@ RSpec.describe Repository do
end
end
describe
'#search_branch_names'
do
subject
(
:search_branch_names
)
{
repository
.
search_branch_names
(
'conflict-*'
)
}
it
'returns matching branch names'
do
expect
(
search_branch_names
).
to
contain_exactly
(
'conflict-binary-file'
,
'conflict-resolvable'
,
'conflict-contains-conflict-markers'
,
'conflict-missing-side'
,
'conflict-start'
,
'conflict-non-utf8'
,
'conflict-too-large'
)
end
end
describe
'#list_last_commits_for_tree'
do
let
(
:path_to_commit
)
do
{
...
...
This diff is collapsed.
Click to expand it.
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