mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Limit results returned by typeahead query in response to user searches
Summary: Currently, on secure.phabricator.com, if you type "e" we generate about 600 users and ship them over the wire. This takes ~300ms. Instead, limit the results to a superset of what the client will actually show. Test Plan: Ran user typeahead queries, tweaked limit to 1. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D3121
This commit is contained in:
parent
ca91a022fe
commit
9d19a0a8b1
1 changed files with 40 additions and 5 deletions
|
@ -114,13 +114,48 @@ final class PhabricatorTypeaheadCommonDatasourceController
|
||||||
'phid');
|
'phid');
|
||||||
|
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$conn_r = id(new PhabricatorUser())->establishConnection('r');
|
// This is an arbitrary limit which is just larger than any limit we
|
||||||
|
// actually use in the application.
|
||||||
|
|
||||||
|
// TODO: The datasource should pass this in the query.
|
||||||
|
$limit = 15;
|
||||||
|
|
||||||
|
$user_table = new PhabricatorUser();
|
||||||
|
$conn_r = $user_table->establishConnection('r');
|
||||||
$ids = queryfx_all(
|
$ids = queryfx_all(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'SELECT DISTINCT userID FROM %T WHERE token LIKE %>',
|
'SELECT id FROM %T WHERE username LIKE %>
|
||||||
|
ORDER BY username ASC LIMIT %d',
|
||||||
|
$user_table->getTableName(),
|
||||||
|
$query,
|
||||||
|
$limit);
|
||||||
|
$ids = ipull($ids, 'id');
|
||||||
|
|
||||||
|
if (count($ids) < $limit) {
|
||||||
|
// If we didn't find enough username hits, look for real name hits.
|
||||||
|
// We need to pull the entire pagesize so that we end up with the
|
||||||
|
// right number of items if this query returns many duplicate IDs
|
||||||
|
// that we've already selected.
|
||||||
|
|
||||||
|
$realname_ids = queryfx_all(
|
||||||
|
$conn_r,
|
||||||
|
'SELECT DISTINCT userID FROM %T WHERE token LIKE %>
|
||||||
|
ORDER BY token ASC LIMIT %d',
|
||||||
PhabricatorUser::NAMETOKEN_TABLE,
|
PhabricatorUser::NAMETOKEN_TABLE,
|
||||||
$query);
|
$query,
|
||||||
$ids = ipull($ids, 'userID');
|
$limit);
|
||||||
|
$realname_ids = ipull($realname_ids, 'userID');
|
||||||
|
$ids = array_merge($ids, $realname_ids);
|
||||||
|
|
||||||
|
$ids = array_unique($ids);
|
||||||
|
$ids = array_slice($ids, 0, $limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always add the logged-in user because some tokenizers autosort them
|
||||||
|
// first. They'll be filtered out on the client side if they don't
|
||||||
|
// match the query.
|
||||||
|
$ids[] = $request->getUser()->getID();
|
||||||
|
|
||||||
if ($ids) {
|
if ($ids) {
|
||||||
$users = id(new PhabricatorUser())->loadColumnsWhere(
|
$users = id(new PhabricatorUser())->loadColumnsWhere(
|
||||||
$columns,
|
$columns,
|
||||||
|
|
Loading…
Reference in a new issue