Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
c5661b0f
Unverified
Commit
c5661b0f
authored
5 years ago
by
Eugen Rochko
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix account search always returning exact match on paginated results (#11525)
Fix #11365
parent
7a1f8a58
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/services/account_search_service.rb
+31
-13
31 additions, 13 deletions
app/services/account_search_service.rb
with
31 additions
and
13 deletions
app/services/account_search_service.rb
+
31
−
13
View file @
c5661b0f
...
...
@@ -21,18 +21,22 @@ class AccountSearchService < BaseService
if
resolving_non_matching_remote_account?
[
ResolveAccountService
.
new
.
call
(
"
#{
query_username
}
@
#{
query_domain
}
"
)].
compact
else
search_results_and_exact_match
.
compact
.
uniq
.
slice
(
0
,
limit
)
search_results_and_exact_match
.
compact
.
uniq
end
end
def
resolving_non_matching_remote_account?
options
[
:resolve
]
&&
!
exact_match
&&
!
domain_is_local?
offset
.
zero?
&&
options
[
:resolve
]
&&
!
exact_match
?
&&
!
domain_is_local?
end
def
search_results_and_exact_match
exact
=
[
exact_match
]
return
exact
if
!
exact
[
0
].
nil?
&&
limit
==
1
exact
+
search_results
.
to_a
return
search_results
.
to_a
unless
offset
.
zero?
results
=
[
exact_match
]
return
results
if
exact_match?
&&
limit
==
1
results
+
search_results
.
to_a
end
def
query_blank_or_hashtag?
...
...
@@ -40,15 +44,15 @@ class AccountSearchService < BaseService
end
def
split_query_string
@
_
split_query_string
||=
query
.
gsub
(
/\A@/
,
''
).
split
(
'@'
)
@split_query_string
||=
query
.
gsub
(
/\A@/
,
''
).
split
(
'@'
)
end
def
query_username
@
_
query_username
||=
split_query_string
.
first
||
''
@query_username
||=
split_query_string
.
first
||
''
end
def
query_domain
@
_
query_domain
||=
query_without_split?
?
nil
:
split_query_string
.
last
@query_domain
||=
query_without_split?
?
nil
:
split_query_string
.
last
end
def
query_without_split?
...
...
@@ -56,15 +60,21 @@ class AccountSearchService < BaseService
end
def
domain_is_local?
@
_
domain_is_local
||=
TagManager
.
instance
.
local_domain?
(
query_domain
)
@domain_is_local
||=
TagManager
.
instance
.
local_domain?
(
query_domain
)
end
def
search_from
options
[
:following
]
&&
account
?
account
.
following
:
Account
end
def
exact_match?
exact_match
.
present?
end
def
exact_match
@_exact_match
||=
begin
return
@exact_match
if
defined?
(
@exact_match
)
@exact_match
=
begin
if
domain_is_local?
search_from
.
without_suspended
.
find_local
(
query_username
)
else
...
...
@@ -74,7 +84,7 @@ class AccountSearchService < BaseService
end
def
search_results
@
_
search_results
||=
begin
@search_results
||=
begin
if
account
advanced_search_results
else
...
...
@@ -84,11 +94,19 @@ class AccountSearchService < BaseService
end
def
advanced_search_results
Account
.
advanced_search_for
(
terms_for_query
,
account
,
limit
,
options
[
:following
],
offset
)
Account
.
advanced_search_for
(
terms_for_query
,
account
,
limit
_for_non_exact_results
,
options
[
:following
],
offset
)
end
def
simple_search_results
Account
.
search_for
(
terms_for_query
,
limit
,
offset
)
Account
.
search_for
(
terms_for_query
,
limit_for_non_exact_results
,
offset
)
end
def
limit_for_non_exact_results
if
offset
.
zero?
&&
exact_match?
limit
-
1
else
limit
end
end
def
terms_for_query
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment