summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/users
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-20 04:59:04 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-20 04:59:04 +0900
commit9536d76b611b42a0e70dcabbf53443181b3e5277 (patch)
tree7a765b30bace5f9f447900c1497887ed607dc43b /src/server/api/endpoints/users
parent4.25.0 (diff)
downloadsharkey-9536d76b611b42a0e70dcabbf53443181b3e5277.tar.gz
sharkey-9536d76b611b42a0e70dcabbf53443181b3e5277.tar.bz2
sharkey-9536d76b611b42a0e70dcabbf53443181b3e5277.zip
Improve 賢さ
Diffstat (limited to 'src/server/api/endpoints/users')
-rw-r--r--src/server/api/endpoints/users/search_by_username.ts26
1 files changed, 25 insertions, 1 deletions
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,7 +21,7 @@ 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
@@ -31,6 +31,30 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
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({
+ host: { $ne: null },
usernameLower: new RegExp(escapeRegexp(query.toLowerCase()))
}, {
limit: limit - users.length