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:
parent
41c87074e6
commit
1c67c26bd8
325 changed files with 1314 additions and 1494 deletions
|
|
@ -47,7 +47,7 @@ export async function createImage(actor: CacheableRemoteUser, value: any): Promi
|
|||
uri: image.url,
|
||||
});
|
||||
|
||||
file = await DriveFiles.findOneOrFail(file.id);
|
||||
file = await DriveFiles.findOneByOrFail({ id: file.id });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
|||
const uri = getApId(note.inReplyTo);
|
||||
if (uri.startsWith(config.url + '/')) {
|
||||
const id = uri.split('/').pop();
|
||||
const talk = await MessagingMessages.findOne(id);
|
||||
const talk = await MessagingMessages.findOneBy({ id });
|
||||
if (talk) {
|
||||
isTalk = true;
|
||||
return null;
|
||||
|
|
@ -201,7 +201,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
|||
|
||||
// vote
|
||||
if (reply && reply.hasPoll) {
|
||||
const poll = await Polls.findOneOrFail(reply.id);
|
||||
const poll = await Polls.findOneByOrFail({ noteId: reply.id });
|
||||
|
||||
const tryCreateVote = async (name: string, index: number): Promise<null> => {
|
||||
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
|
||||
|
|
@ -306,7 +306,7 @@ export async function extractEmojis(tags: IObject | IObject[], host: string): Pr
|
|||
const name = tag.name!.replace(/^:/, '').replace(/:$/, '');
|
||||
tag.icon = toSingle(tag.icon);
|
||||
|
||||
const exists = await Emojis.findOne({
|
||||
const exists = await Emojis.findOneBy({
|
||||
host,
|
||||
name,
|
||||
});
|
||||
|
|
@ -327,7 +327,7 @@ export async function extractEmojis(tags: IObject | IObject[], host: string): Pr
|
|||
updatedAt: new Date(),
|
||||
});
|
||||
|
||||
return await Emojis.findOne({
|
||||
return await Emojis.findOneBy({
|
||||
host,
|
||||
name,
|
||||
}) as Emoji;
|
||||
|
|
@ -347,6 +347,6 @@ export async function extractEmojis(tags: IObject | IObject[], host: string): Pr
|
|||
publicUrl: tag.icon!.url,
|
||||
updatedAt: new Date(),
|
||||
aliases: [],
|
||||
} as Partial<Emoji>).then(x => Emojis.findOneOrFail(x.identifiers[0]));
|
||||
} as Partial<Emoji>).then(x => Emojis.findOneByOrFail(x.identifiers[0]));
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import { UserPublickey } from '@/models/entities/user-publickey.js';
|
|||
import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error.js';
|
||||
import { toPuny } from '@/misc/convert-host.js';
|
||||
import { UserProfile } from '@/models/entities/user-profile.js';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { toArray } from '@/prelude/array.js';
|
||||
import { fetchInstanceMetadata } from '@/services/fetch-instance-metadata.js';
|
||||
import { normalizeForSearch } from '@/misc/normalize-for-search.js';
|
||||
|
|
@ -32,6 +31,7 @@ import { truncate } from '@/misc/truncate.js';
|
|||
import { StatusError } from '@/misc/fetch.js';
|
||||
import { uriPersonCache } from '@/services/user-cache.js';
|
||||
import { publishInternalEvent } from '@/services/stream.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
|
||||
const logger = apLogger;
|
||||
|
||||
|
|
@ -102,13 +102,13 @@ export async function fetchPerson(uri: string, resolver?: Resolver): Promise<Cac
|
|||
// URIがこのサーバーを指しているならデータベースからフェッチ
|
||||
if (uri.startsWith(config.url + '/')) {
|
||||
const id = uri.split('/').pop();
|
||||
const u = await Users.findOne(id).then(x => x || null); // TODO: typeorm 3.0 にしたら .then(x => x || null) を消す
|
||||
const u = await Users.findOneBy({ id });
|
||||
if (u) uriPersonCache.set(uri, u);
|
||||
return u;
|
||||
}
|
||||
|
||||
//#region このサーバーに既に登録されていたらそれを返す
|
||||
const exist = await Users.findOne({ uri });
|
||||
const exist = await Users.findOneBy({ uri });
|
||||
|
||||
if (exist) {
|
||||
uriPersonCache.set(uri, exist);
|
||||
|
|
@ -151,7 +151,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
|||
let user: IRemoteUser;
|
||||
try {
|
||||
// Start transaction
|
||||
await getConnection().transaction(async transactionalEntityManager => {
|
||||
await db.transaction(async transactionalEntityManager => {
|
||||
user = await transactionalEntityManager.save(new User({
|
||||
id: genId(),
|
||||
avatarId: null,
|
||||
|
|
@ -197,7 +197,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
|||
// duplicate key error
|
||||
if (isDuplicateKeyValueError(e)) {
|
||||
// /users/@a => /users/:id のように入力がaliasなときにエラーになることがあるのを対応
|
||||
const u = await Users.findOne({
|
||||
const u = await Users.findOneBy({
|
||||
uri: person.id,
|
||||
});
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
|
|||
}
|
||||
|
||||
//#region このサーバーに既に登録されているか
|
||||
const exist = await Users.findOne({ uri }) as IRemoteUser;
|
||||
const exist = await Users.findOneBy({ uri }) as IRemoteUser;
|
||||
|
||||
if (exist == null) {
|
||||
return;
|
||||
|
|
@ -451,7 +451,7 @@ export function analyzeAttachments(attachments: IObject | IObject[] | undefined)
|
|||
}
|
||||
|
||||
export async function updateFeatured(userId: User['id']) {
|
||||
const user = await Users.findOneOrFail(userId);
|
||||
const user = await Users.findOneByOrFail({ id: userId });
|
||||
if (!Users.isRemoteUser(user)) return;
|
||||
if (!user.featured) return;
|
||||
|
||||
|
|
@ -474,7 +474,7 @@ export async function updateFeatured(userId: User['id']) {
|
|||
.slice(0, 5)
|
||||
.map(item => limit(() => resolveNote(item, resolver))));
|
||||
|
||||
await getConnection().transaction(async transactionalEntityManager => {
|
||||
await db.transaction(async transactionalEntityManager => {
|
||||
await transactionalEntityManager.delete(UserNotePining, { userId: user.id });
|
||||
|
||||
// とりあえずidを別の時間で生成して順番を維持
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ export async function updateQuestion(value: any) {
|
|||
if (uri.startsWith(config.url + '/')) throw new Error('uri points local');
|
||||
|
||||
//#region このサーバーに既に登録されているか
|
||||
const note = await Notes.findOne({ uri });
|
||||
const note = await Notes.findOneBy({ uri });
|
||||
if (note == null) throw new Error('Question is not registed');
|
||||
|
||||
const poll = await Polls.findOne({ noteId: note.id });
|
||||
const poll = await Polls.findOneBy({ noteId: note.id });
|
||||
if (poll == null) throw new Error('Question is not registed');
|
||||
//#endregion
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue