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
01083870
Commit
01083870
authored
Nov 08, 2016
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'faster_project_search' into 'master'
Faster search inside Project See merge request !7353
parents
358e8141
869696bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
18 deletions
+33
-18
app/models/repository.rb
app/models/repository.rb
+4
-0
changelogs/unreleased/faster_project_search.yml
changelogs/unreleased/faster_project_search.yml
+4
-0
lib/gitlab/project_search_results.rb
lib/gitlab/project_search_results.rb
+12
-18
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+13
-0
No files found.
app/models/repository.rb
View file @
01083870
...
@@ -1064,6 +1064,10 @@ class Repository
...
@@ -1064,6 +1064,10 @@ class Repository
end
end
def
search_files
(
query
,
ref
)
def
search_files
(
query
,
ref
)
unless
exists?
&&
has_visible_content?
&&
query
.
present?
return
[]
end
offset
=
2
offset
=
2
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
grep -i -I -n --before-context
#{
offset
}
--after-context
#{
offset
}
-E -e
#{
Regexp
.
escape
(
query
)
}
#{
ref
||
root_ref
}
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
grep -i -I -n --before-context
#{
offset
}
--after-context
#{
offset
}
-E -e
#{
Regexp
.
escape
(
query
)
}
#{
ref
||
root_ref
}
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
scrub
.
split
(
/^--$/
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
scrub
.
split
(
/^--$/
)
...
...
changelogs/unreleased/faster_project_search.yml
0 → 100644
View file @
01083870
---
title
:
Faster search inside Project
merge_request
:
author
:
lib/gitlab/project_search_results.rb
View file @
01083870
...
@@ -5,11 +5,7 @@ module Gitlab
...
@@ -5,11 +5,7 @@ module Gitlab
def
initialize
(
current_user
,
project
,
query
,
repository_ref
=
nil
)
def
initialize
(
current_user
,
project
,
query
,
repository_ref
=
nil
)
@current_user
=
current_user
@current_user
=
current_user
@project
=
project
@project
=
project
@repository_ref
=
if
repository_ref
.
present?
@repository_ref
=
repository_ref
.
presence
repository_ref
else
nil
end
@query
=
query
@query
=
query
end
end
...
@@ -47,33 +43,31 @@ module Gitlab
...
@@ -47,33 +43,31 @@ module Gitlab
private
private
def
blobs
def
blobs
if
project
.
empty_repo?
||
query
.
blank?
@blobs
||=
project
.
repository
.
search_files
(
query
,
repository_ref
)
[]
else
project
.
repository
.
search_files
(
query
,
repository_ref
)
end
end
end
def
wiki_blobs
def
wiki_blobs
if
project
.
wiki_enabled?
&&
query
.
present?
@wiki_blobs
||=
begin
project_wiki
=
ProjectWiki
.
new
(
project
)
if
project
.
wiki_enabled?
&&
query
.
present?
project_wiki
=
ProjectWiki
.
new
(
project
)
unless
project_wiki
.
empty?
unless
project_wiki
.
empty?
project_wiki
.
search_files
(
query
)
project_wiki
.
search_files
(
query
)
else
[]
end
else
else
[]
[]
end
end
else
[]
end
end
end
end
def
notes
def
notes
project
.
notes
.
user
.
search
(
query
,
as_user:
@current_user
).
order
(
'updated_at DESC'
)
@notes
||=
project
.
notes
.
user
.
search
(
query
,
as_user:
@current_user
).
order
(
'updated_at DESC'
)
end
end
def
commits
def
commits
project
.
repository
.
find_commits_by_message
(
query
)
@commits
||=
project
.
repository
.
find_commits_by_message
(
query
)
end
end
def
project_ids_relation
def
project_ids_relation
...
...
spec/models/repository_spec.rb
View file @
01083870
...
@@ -362,6 +362,19 @@ describe Repository, models: true do
...
@@ -362,6 +362,19 @@ describe Repository, models: true do
expect
(
results
.
first
).
not_to
start_with
(
'fatal:'
)
expect
(
results
.
first
).
not_to
start_with
(
'fatal:'
)
end
end
it
'properly handles when query is not present'
do
results
=
repository
.
search_files
(
''
,
'master'
)
expect
(
results
).
to
match_array
([])
end
it
'properly handles query when repo is empty'
do
repository
=
create
(
:empty_project
).
repository
results
=
repository
.
search_files
(
'test'
,
'master'
)
expect
(
results
).
to
match_array
([])
end
describe
'result'
do
describe
'result'
do
subject
{
results
.
first
}
subject
{
results
.
first
}
...
...
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