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

@ -8,14 +8,15 @@ import { Users, Relays } from '@/models/index.js';
import { genId } from '@/misc/gen-id.js';
import { Cache } from '@/misc/cache.js';
import { Relay } from '@/models/entities/relay.js';
import { IsNull } from 'typeorm';
const ACTOR_USERNAME = 'relay.actor' as const;
const relaysCache = new Cache<Relay[]>(1000 * 60 * 10);
export async function getRelayActor(): Promise<ILocalUser> {
const user = await Users.findOne({
host: null,
const user = await Users.findOneBy({
host: IsNull(),
username: ACTOR_USERNAME,
});
@ -30,7 +31,7 @@ export async function addRelay(inbox: string) {
id: genId(),
inbox,
status: 'requesting',
}).then(x => Relays.findOneOrFail(x.identifiers[0]));
}).then(x => Relays.findOneByOrFail(x.identifiers[0]));
const relayActor = await getRelayActor();
const follow = await renderFollowRelay(relay, relayActor);
@ -41,7 +42,7 @@ export async function addRelay(inbox: string) {
}
export async function removeRelay(inbox: string) {
const relay = await Relays.findOne({
const relay = await Relays.findOneBy({
inbox,
});
@ -82,7 +83,7 @@ export async function relayRejected(id: string) {
export async function deliverToRelays(user: { id: User['id']; host: null; }, activity: any) {
if (activity == null) return;
const relays = await relaysCache.fetch(null, () => Relays.find({
const relays = await relaysCache.fetch(null, () => Relays.findBy({
status: 'accepted',
}));
if (relays.length === 0) return;