From 1471e523079294d41821d5f5fb30c25269390d20 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 21 Mar 2020 12:48:25 +0900 Subject: [PATCH] Resolve #6110 --- .../api/endpoints/users/search-by-username-and-host.ts | 7 +++++-- src/server/api/endpoints/users/search.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/server/api/endpoints/users/search-by-username-and-host.ts b/src/server/api/endpoints/users/search-by-username-and-host.ts index 81ff19ff6f..bc68f44094 100644 --- a/src/server/api/endpoints/users/search-by-username-and-host.ts +++ b/src/server/api/endpoints/users/search-by-username-and-host.ts @@ -1,7 +1,6 @@ import $ from 'cafy'; import define from '../../define'; import { Users } from '../../../../models'; -import { User } from '../../../../models/entities/user'; export const meta = { desc: { @@ -73,14 +72,17 @@ export default define(meta, async (ps, me) => { q.andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' }) } + q.orderBy('user.updatedAt', 'DESC'); + const users = await q.take(ps.limit!).skip(ps.offset).getMany(); return await Users.packMany(users, me, { detail: ps.detail }); - } else { + } else if (ps.username) { let users = await Users.createQueryBuilder('user') .where('user.host IS NULL') .andWhere('user.isSuspended = FALSE') .andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' }) + .orderBy('user.updatedAt', 'DESC') .take(ps.limit!) .skip(ps.offset) .getMany(); @@ -90,6 +92,7 @@ export default define(meta, async (ps, me) => { .where('user.host IS NOT NULL') .andWhere('user.isSuspended = FALSE') .andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' }) + .orderBy('user.updatedAt', 'DESC') .take(ps.limit! - users.length) .getMany(); diff --git a/src/server/api/endpoints/users/search.ts b/src/server/api/endpoints/users/search.ts index dbeb6eb6af..c01f355d8c 100644 --- a/src/server/api/endpoints/users/search.ts +++ b/src/server/api/endpoints/users/search.ts @@ -74,6 +74,7 @@ export default define(meta, async (ps, me) => { .where('user.host IS NULL') .andWhere('user.isSuspended = FALSE') .andWhere('user.usernameLower like :username', { username: ps.query.replace('@', '').toLowerCase() + '%' }) + .orderBy('user.updatedAt', 'DESC') .take(ps.limit!) .skip(ps.offset) .getMany(); @@ -83,6 +84,7 @@ export default define(meta, async (ps, me) => { .where('user.host IS NOT NULL') .andWhere('user.isSuspended = FALSE') .andWhere('user.usernameLower like :username', { username: ps.query.replace('@', '').toLowerCase() + '%' }) + .orderBy('user.updatedAt', 'DESC') .take(ps.limit! - users.length) .getMany();