From 9536d76b611b42a0e70dcabbf53443181b3e5277 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 20 Jul 2018 04:59:04 +0900 Subject: [PATCH] =?UTF-8?q?Improve=20=E8=B3=A2=E3=81=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/endpoints/users/search_by_username.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/server/api/endpoints/users/search_by_username.ts b/src/server/api/endpoints/users/search_by_username.ts index d347ba6056..1d8553baef 100644 --- a/src/server/api/endpoints/users/search_by_username.ts +++ b/src/server/api/endpoints/users/search_by_username.ts @@ -21,12 +21,36 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => let users = await User .find({ host: null, - usernameLower: new RegExp(escapeRegexp(query.toLowerCase())) + usernameLower: new RegExp('^' + escapeRegexp(query.toLowerCase())) }, { limit: limit, skip: offset }); + if (users.length < limit) { + const remoteUsers = await User + .find({ + host: { $ne: null }, + usernameLower: new RegExp('^' + escapeRegexp(query.toLowerCase())) + }, { + limit: limit - users.length + }); + + users = users.concat(remoteUsers); + } + + if (users.length < limit) { + const remoteUsers = await User + .find({ + host: null, + usernameLower: new RegExp(escapeRegexp(query.toLowerCase())) + }, { + limit: limit - users.length + }); + + users = users.concat(remoteUsers); + } + if (users.length < limit) { const remoteUsers = await User .find({