Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユーザー検索ではフォロー中の非アクティブなユーザーがサジェストされなくなる? #14793

Open
1 task
Sayamame-beans opened this issue Oct 20, 2024 · 1 comment
Labels
🐛Bug Unexpected behavior packages/backend Server side specific issue/PR

Comments

@Sayamame-beans
Copy link
Member

💡 Summary

詳細まで調査出来ていませんが、恐らく #14149 と同じ現象が起きていると思われる事象があったため、報告します。

🥰 Expected Behavior

非アクティブなユーザーでもユーザー検索で表示される

🤬 Actual Behavior

非アクティブなユーザーがユーザー検索で表示されないことがある

📝 Steps to Reproduce

💻 Frontend Environment

* Model and OS of the device(s): any
* Browser: any
* Server URL: https://misskey.niri.la
* Misskey: 2024.10.0-kinel.1

🛰 Backend Environment (for server admin)

* Installation Method or Hosting Service:
* Misskey:
* Node:
* PostgreSQL:
* Redis:
* OS and Architecture:

Do you want to address this bug yourself?

  • Yes, I will patch the bug myself and send a pull request
@Sayamame-beans Sayamame-beans added the ⚠️bug? This might be a bug label Oct 20, 2024
@KisaragiEffective KisaragiEffective added the packages/frontend Client side specific issue/PR label Oct 20, 2024
@kakkokari-gtyih kakkokari-gtyih added packages/backend Server side specific issue/PR and removed packages/frontend Client side specific issue/PR labels Oct 20, 2024
@samunohito samunohito added 🐛Bug Unexpected behavior and removed ⚠️bug? This might be a bug labels Nov 17, 2024
@samunohito
Copy link
Member

super(meta, paramDef, async (ps, me) => {
const activeThreshold = new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)); // 30日
ps.query = ps.query.trim();
const isUsername = ps.query.startsWith('@') && !ps.query.includes(' ') && ps.query.indexOf('@', 1) === -1;
let users: MiUser[] = [];
const nameQuery = this.usersRepository.createQueryBuilder('user')
.where(new Brackets(qb => {
qb.where('user.name ILIKE :query', { query: '%' + sqlLikeEscape(ps.query) + '%' });
if (isUsername) {
qb.orWhere('user.usernameLower LIKE :username', { username: sqlLikeEscape(ps.query.replace('@', '').toLowerCase()) + '%' });
} else if (this.userEntityService.validateLocalUsername(ps.query)) { // Also search username if it qualifies as username
qb.orWhere('user.usernameLower LIKE :username', { username: '%' + sqlLikeEscape(ps.query.toLowerCase()) + '%' });
}
}))
.andWhere(new Brackets(qb => {
qb
.where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold: activeThreshold });
}))
.andWhere('user.isSuspended = FALSE');
if (ps.origin === 'local') {
nameQuery.andWhere('user.host IS NULL');
} else if (ps.origin === 'remote') {
nameQuery.andWhere('user.host IS NOT NULL');
}
users = await nameQuery
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
.limit(ps.limit)
.offset(ps.offset)
.getMany();
if (users.length < ps.limit) {
const profQuery = this.userProfilesRepository.createQueryBuilder('prof')
.select('prof.userId')
.where('prof.description ILIKE :query', { query: '%' + sqlLikeEscape(ps.query) + '%' });
if (ps.origin === 'local') {
profQuery.andWhere('prof.userHost IS NULL');
} else if (ps.origin === 'remote') {
profQuery.andWhere('prof.userHost IS NOT NULL');
}
const query = this.usersRepository.createQueryBuilder('user')
.where(`user.id IN (${ profQuery.getQuery() })`)
.andWhere(new Brackets(qb => {
qb
.where('user.updatedAt IS NULL')
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold: activeThreshold });
}))
.andWhere('user.isSuspended = FALSE')
.setParameters(profQuery.getParameters());
users = users.concat(await query
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
.limit(ps.limit)
.offset(ps.offset)
.getMany(),
);
}
return await this.userEntityService.packMany(users, me, { schema: ps.detail ? 'UserDetailed' : 'UserLite' });
});

実装整理

◎1回目の検索(最終更新日時の降順)

  • ユーザ名(@[email protected]のような書式)で検索しているか
    • YES: クエリから頭の@を除いた文字列でuser.usernameLowerを前方一致検索
    • NO: クエリ文字列でuser.usernameLowerを部分一致検索
  • 最終更新日時が30日より少ない or 最終更新日時が存在しない
  • サスペンドされていない
  • リモートかローカルか

◎2回目の検索(1回目で所定の件数に満たないとき / 最終更新日時の降順)

  • クエリ文字列で userProfile.description を部分一致検索
  • 最終更新日時が30日より少ない or 最終更新日時が存在しない
  • サスペンドされていない
  • リモートかローカルか

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛Bug Unexpected behavior packages/backend Server side specific issue/PR
Projects
Development

No branches or pull requests

4 participants