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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
9e203582
Commit
9e203582
authored
Aug 23, 2017
by
Hiroyuki Sato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve AutocompleteController#user.json performance
parent
539ed0a6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
7 deletions
+89
-7
app/models/user.rb
app/models/user.rb
+1
-1
changelogs/unreleased/improve-autocomplete-user-performance.yml
...logs/unreleased/improve-autocomplete-user-performance.yml
+5
-0
lib/gitlab/sql/pattern.rb
lib/gitlab/sql/pattern.rb
+29
-0
spec/features/issues/filtered_search/dropdown_author_spec.rb
spec/features/issues/filtered_search/dropdown_author_spec.rb
+6
-6
spec/lib/gitlab/sql/pattern_spec.rb
spec/lib/gitlab/sql/pattern_spec.rb
+31
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+17
-0
No files found.
app/models/user.rb
View file @
9e203582
...
...
@@ -303,7 +303,7 @@ class User < ActiveRecord::Base
# Returns an ActiveRecord::Relation.
def
search
(
query
)
table
=
arel_table
pattern
=
"%
#{
query
}
%"
pattern
=
Gitlab
::
SQL
::
Pattern
.
new
(
query
).
to_sql
order
=
<<~
SQL
CASE
...
...
changelogs/unreleased/improve-autocomplete-user-performance.yml
0 → 100644
View file @
9e203582
---
title
:
Improve performance for AutocompleteController#users.json
merge_request
:
13754
author
:
Hiroyuki Sato
type
:
changed
lib/gitlab/sql/pattern.rb
0 → 100644
View file @
9e203582
module
Gitlab
module
SQL
class
Pattern
MIN_CHARS_FOR_PARTIAL_MATCHING
=
3
attr_reader
:query
def
initialize
(
query
)
@query
=
query
end
def
to_sql
if
exact_matching?
query
else
"%
#{
query
}
%"
end
end
def
exact_matching?
!
partial_matching?
end
def
partial_matching?
@query
.
length
>=
MIN_CHARS_FOR_PARTIAL_MATCHING
end
end
end
end
spec/features/issues/filtered_search/dropdown_author_spec.rb
View file @
9e203582
...
...
@@ -6,7 +6,7 @@ describe 'Dropdown author', js: true do
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:user
)
{
create
(
:user
,
name:
'administrator'
,
username:
'root'
)
}
let!
(
:user_john
)
{
create
(
:user
,
name:
'John'
,
username:
'th0mas'
)
}
let!
(
:user_jacob
)
{
create
(
:user
,
name:
'Jacob'
,
username:
'o
t
ter32'
)
}
let!
(
:user_jacob
)
{
create
(
:user
,
name:
'Jacob'
,
username:
'o
o
ter32'
)
}
let
(
:filtered_search
)
{
find
(
'.filtered-search'
)
}
let
(
:js_dropdown_author
)
{
'#js-dropdown-author'
}
...
...
@@ -82,31 +82,31 @@ describe 'Dropdown author', js: true do
end
it
'filters by name'
do
send_keys_to_filtered_search
(
'ja'
)
send_keys_to_filtered_search
(
'ja
c
'
)
expect
(
dropdown_author_size
).
to
eq
(
1
)
end
it
'filters by case insensitive name'
do
send_keys_to_filtered_search
(
'Ja'
)
send_keys_to_filtered_search
(
'Ja
c
'
)
expect
(
dropdown_author_size
).
to
eq
(
1
)
end
it
'filters by username with symbol'
do
send_keys_to_filtered_search
(
'@ot'
)
send_keys_to_filtered_search
(
'@o
o
t'
)
expect
(
dropdown_author_size
).
to
eq
(
2
)
end
it
'filters by username without symbol'
do
send_keys_to_filtered_search
(
'ot'
)
send_keys_to_filtered_search
(
'o
o
t'
)
expect
(
dropdown_author_size
).
to
eq
(
2
)
end
it
'filters by case insensitive username without symbol'
do
send_keys_to_filtered_search
(
'OT'
)
send_keys_to_filtered_search
(
'O
O
T'
)
expect
(
dropdown_author_size
).
to
eq
(
2
)
end
...
...
spec/lib/gitlab/sql/pattern_spec.rb
0 → 100644
View file @
9e203582
require
'spec_helper'
describe
Gitlab
::
SQL
::
Pattern
do
describe
'#to_sql'
do
subject
(
:to_sql
)
{
described_class
.
new
(
query
).
to_sql
}
context
'when a query is shorter than 3 chars'
do
let
(
:query
)
{
'12'
}
it
'returns exact matching pattern'
do
expect
(
to_sql
).
to
eq
(
'12'
)
end
end
context
'when a query is equal to 3 chars'
do
let
(
:query
)
{
'123'
}
it
'returns partial matching pattern'
do
expect
(
to_sql
).
to
eq
(
'%123%'
)
end
end
context
'when a query is longer than 3 chars'
do
let
(
:query
)
{
'1234'
}
it
'returns partial matching pattern'
do
expect
(
to_sql
).
to
eq
(
'%1234%'
)
end
end
end
end
spec/models/user_spec.rb
View file @
9e203582
...
...
@@ -789,6 +789,7 @@ describe User do
describe
'.search'
do
let!
(
:user
)
{
create
(
:user
,
name:
'user'
,
username:
'usern'
,
email:
'email@gmail.com'
)
}
let!
(
:user2
)
{
create
(
:user
,
name:
'user name'
,
username:
'username'
,
email:
'someemail@gmail.com'
)
}
let!
(
:user3
)
{
create
(
:user
,
name:
'us'
,
username:
'se'
,
email:
'foo@gmail.com'
)
}
describe
'name matching'
do
it
'returns users with a matching name with exact match first'
do
...
...
@@ -802,6 +803,14 @@ describe User do
it
'returns users with a matching name regardless of the casing'
do
expect
(
described_class
.
search
(
user2
.
name
.
upcase
)).
to
eq
([
user2
])
end
it
'returns users with a exact matching name shorter than 3 chars'
do
expect
(
described_class
.
search
(
user3
.
name
)).
to
eq
([
user3
])
end
it
'returns users with a exact matching name shorter than 3 chars regardless of the casing'
do
expect
(
described_class
.
search
(
user3
.
name
.
upcase
)).
to
eq
([
user3
])
end
end
describe
'email matching'
do
...
...
@@ -830,6 +839,14 @@ describe User do
it
'returns users with a matching username regardless of the casing'
do
expect
(
described_class
.
search
(
user2
.
username
.
upcase
)).
to
eq
([
user2
])
end
it
'returns users with a exact matching username shorter than 3 chars'
do
expect
(
described_class
.
search
(
user3
.
username
)).
to
eq
([
user3
])
end
it
'returns users with a exact matching username shorter than 3 chars regardless of the casing'
do
expect
(
described_class
.
search
(
user3
.
username
.
upcase
)).
to
eq
([
user3
])
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