fix(backend): 年越しの時期で誕生日検索クエリーが誤動作する問題を修正 (MisskeyIO#577)

This commit is contained in:
まっちゃとーにゅ 2024-03-29 20:41:27 +09:00 committed by GitHub
parent 59687b418d
commit 38581006be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { Brackets } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type {
FollowingsRepository,
@ -90,8 +91,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.innerJoin(this.userProfilesRepository.metadata.targetName, 'followeeProfile', 'followeeProfile.userId = following.followeeId');
if (Object.hasOwn(ps.birthday, 'begin') && Object.hasOwn(ps.birthday, 'end')) {
const { begin, end } = ps.birthday as { begin: { month: number; day: number }; end: { month: number; day: number }; };
query.andWhere('get_birthday_date(followeeProfile.birthday) BETWEEN :begin AND :end', { begin: begin.month * 100 + begin.day, end: end.month * 100 + end.day });
const range = ps.birthday as { begin: { month: number; day: number }; end: { month: number; day: number }; };
const begin = range.begin.month * 100 + range.begin.day;
const end = range.end.month * 100 + range.end.day;
if (begin <= end) {
query.andWhere('get_birthday_date(followeeProfile.birthday) BETWEEN :begin AND :end', { begin, end });
} else {
// 12/31 から 1/1 の範囲を取得するために OR で対応
query.andWhere(new Brackets(qb => {
qb.where('get_birthday_date(followeeProfile.birthday) BETWEEN :begin AND 1231', { begin });
qb.orWhere('get_birthday_date(followeeProfile.birthday) BETWEEN 101 AND :end', { end });
}));
}
} else {
const { month, day } = ps.birthday as { month: number; day: number };
// なぜか get_birthday_date() = :birthday だとインデックスが効かないので、BETWEEN で対応