enhance: ユーザー検索の精度を強化

This commit is contained in:
syuilo 2021-10-17 16:26:35 +09:00
parent 0c21ae226b
commit dec69cc67b
5 changed files with 103 additions and 64 deletions

View file

@ -1,6 +1,8 @@
import $ from 'cafy';
import define from '../../define';
import { Users } from '@/models/index';
import { Brackets } from 'typeorm';
import { USER_ACTIVE_THRESHOLD } from '@/const';
export const meta = {
tags: ['users'],
@ -64,8 +66,11 @@ export default define(meta, async (ps, me) => {
.where('user.host IS NULL')
.andWhere('user.isSuspended = FALSE')
.andWhere('user.usernameLower like :username', { username: ps.username.toLowerCase() + '%' })
.andWhere('user.updatedAt IS NOT NULL')
.orderBy('user.updatedAt', 'DESC')
.andWhere(new Brackets(qb => { qb
.where('user.lastActiveDate IS NULL')
.orWhere('user.lastActiveDate > :activeThreshold', { activeThreshold: new Date(Date.now() - USER_ACTIVE_THRESHOLD) });
}))
.orderBy('user.lastActiveDate', 'DESC', 'NULLS LAST')
.take(ps.limit!)
.skip(ps.offset)
.getMany();