refactor: migrate to typeorm 3.0 (#8443)

* wip

* wip

* wip

* Update following.ts

* wip

* wip

* wip

* Update resolve-user.ts

* maxQueryExecutionTime

* wip

* wip
This commit is contained in:
syuilo 2022-03-26 15:34:00 +09:00 committed by GitHub
parent 41c87074e6
commit 1c67c26bd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
325 changed files with 1314 additions and 1494 deletions

View file

@ -7,15 +7,16 @@ import chalk from 'chalk';
import { User, IRemoteUser } from '@/models/entities/user.js';
import { Users } from '@/models/index.js';
import { toPuny } from '@/misc/convert-host.js';
import { IsNull } from 'typeorm';
const logger = remoteLogger.createSubLogger('resolve-user');
export async function resolveUser(username: string, host: string | null, option?: any, resync = false): Promise<User> {
export async function resolveUser(username: string, host: string | null): Promise<User> {
const usernameLower = username.toLowerCase();
if (host == null) {
logger.info(`return local user: ${usernameLower}`);
return await Users.findOne({ usernameLower, host: null }).then(u => {
return await Users.findOneBy({ usernameLower, host: IsNull() }).then(u => {
if (u == null) {
throw new Error('user not found');
} else {
@ -28,7 +29,7 @@ export async function resolveUser(username: string, host: string | null, option?
if (config.host === host) {
logger.info(`return local user: ${usernameLower}`);
return await Users.findOne({ usernameLower, host: null }).then(u => {
return await Users.findOneBy({ usernameLower, host: IsNull() }).then(u => {
if (u == null) {
throw new Error('user not found');
} else {
@ -37,7 +38,7 @@ export async function resolveUser(username: string, host: string | null, option?
});
}
const user = await Users.findOne({ usernameLower, host }, option) as IRemoteUser | null;
const user = await Users.findOneBy({ usernameLower, host }) as IRemoteUser | null;
const acctLower = `${usernameLower}@${host}`;
@ -48,8 +49,8 @@ export async function resolveUser(username: string, host: string | null, option?
return await createPerson(self.href);
}
// resyncオプション OR ユーザー情報が古い場合は、WebFilgerからやりなおして返す
if (resync || user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) {
// ユーザー情報が古い場合は、WebFilgerからやりなおして返す
if (user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) {
// 繋がらないインスタンスに何回も試行するのを防ぐ, 後続の同様処理の連続試行を防ぐ ため 試行前にも更新する
await Users.update(user.id, {
lastFetchedAt: new Date(),
@ -82,7 +83,7 @@ export async function resolveUser(username: string, host: string | null, option?
await updatePerson(self.href);
logger.info(`return resynced remote user: ${acctLower}`);
return await Users.findOne({ uri: self.href }).then(u => {
return await Users.findOneBy({ uri: self.href }).then(u => {
if (u == null) {
throw new Error('user not found');
} else {