@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+40 -5
+40 -5
src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
··· 114 114 'phid'); 115 115 116 116 if ($query) { 117 - $conn_r = id(new PhabricatorUser())->establishConnection('r'); 117 + // This is an arbitrary limit which is just larger than any limit we 118 + // actually use in the application. 119 + 120 + // TODO: The datasource should pass this in the query. 121 + $limit = 15; 122 + 123 + $user_table = new PhabricatorUser(); 124 + $conn_r = $user_table->establishConnection('r'); 118 125 $ids = queryfx_all( 119 126 $conn_r, 120 - 'SELECT DISTINCT userID FROM %T WHERE token LIKE %>', 121 - PhabricatorUser::NAMETOKEN_TABLE, 122 - $query); 123 - $ids = ipull($ids, 'userID'); 127 + 'SELECT id FROM %T WHERE username LIKE %> 128 + ORDER BY username ASC LIMIT %d', 129 + $user_table->getTableName(), 130 + $query, 131 + $limit); 132 + $ids = ipull($ids, 'id'); 133 + 134 + if (count($ids) < $limit) { 135 + // If we didn't find enough username hits, look for real name hits. 136 + // We need to pull the entire pagesize so that we end up with the 137 + // right number of items if this query returns many duplicate IDs 138 + // that we've already selected. 139 + 140 + $realname_ids = queryfx_all( 141 + $conn_r, 142 + 'SELECT DISTINCT userID FROM %T WHERE token LIKE %> 143 + ORDER BY token ASC LIMIT %d', 144 + PhabricatorUser::NAMETOKEN_TABLE, 145 + $query, 146 + $limit); 147 + $realname_ids = ipull($realname_ids, 'userID'); 148 + $ids = array_merge($ids, $realname_ids); 149 + 150 + $ids = array_unique($ids); 151 + $ids = array_slice($ids, 0, $limit); 152 + } 153 + 154 + // Always add the logged-in user because some tokenizers autosort them 155 + // first. They'll be filtered out on the client side if they don't 156 + // match the query. 157 + $ids[] = $request->getUser()->getID(); 158 + 124 159 if ($ids) { 125 160 $users = id(new PhabricatorUser())->loadColumnsWhere( 126 161 $columns,