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
325 changed files with 1314 additions and 1494 deletions

View File

@ -7,6 +7,6 @@ import { User } from '@/models/entities/user.js';
* @param id Follower|Followee ID
*/
export default async function renderFollowUser(id: User['id']): Promise<any> {
const user = await Users.findOneOrFail(id);
const user = await Users.findOneByOrFail({ id: id });
return Users.isLocalUser(user) ? `${config.url}/users/${user.id}` : user.uri;
}

View File

@ -2,6 +2,7 @@ import config from '@/config/index.js';
import { NoteReaction } from '@/models/entities/note-reaction.js';
import { Note } from '@/models/entities/note.js';
import { Emojis } from '@/models/index.js';
import { IsNull } from 'typeorm';
import renderEmoji from './emoji.js';
export const renderLike = async (noteReaction: NoteReaction, note: Note) => {
@ -18,9 +19,9 @@ export const renderLike = async (noteReaction: NoteReaction, note: Note) => {
if (reaction.startsWith(':')) {
const name = reaction.replace(/:/g, '');
const emoji = await Emojis.findOne({
const emoji = await Emojis.findOneBy({
name,
host: null,
host: IsNull(),
});
if (emoji) object.tag = [ renderEmoji(emoji) ];

View File

@ -7,25 +7,25 @@ import toHtml from '../misc/get-note-html.js';
import { Note, IMentionedRemoteUsers } from '@/models/entities/note.js';
import { DriveFile } from '@/models/entities/drive-file.js';
import { DriveFiles, Notes, Users, Emojis, Polls } from '@/models/index.js';
import { In } from 'typeorm';
import { In, IsNull } from 'typeorm';
import { Emoji } from '@/models/entities/emoji.js';
import { Poll } from '@/models/entities/poll.js';
export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<Record<string, unknown>> {
const getPromisedFiles = async (ids: string[]) => {
if (!ids || ids.length === 0) return [];
const items = await DriveFiles.find({ id: In(ids) });
const items = await DriveFiles.findBy({ id: In(ids) });
return ids.map(id => items.find(item => item.id === id)).filter(item => item != null) as DriveFile[];
};
let inReplyTo;
let inReplyToNote: Note | undefined;
let inReplyToNote: Note | null;
if (note.replyId) {
inReplyToNote = await Notes.findOne(note.replyId);
inReplyToNote = await Notes.findOneBy({ id: note.replyId });
if (inReplyToNote != null) {
const inReplyToUser = await Users.findOne(inReplyToNote.userId);
const inReplyToUser = await Users.findOneBy({ id: inReplyToNote.userId });
if (inReplyToUser != null) {
if (inReplyToNote.uri) {
@ -46,7 +46,7 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
let quote;
if (note.renoteId) {
const renote = await Notes.findOne(note.renoteId);
const renote = await Notes.findOneBy({ id: note.renoteId });
if (renote) {
quote = renote.uri ? renote.uri : `${config.url}/notes/${renote.id}`;
@ -73,7 +73,7 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
to = mentions;
}
const mentionedUsers = note.mentions.length > 0 ? await Users.find({
const mentionedUsers = note.mentions.length > 0 ? await Users.findBy({
id: In(note.mentions),
}) : [];
@ -83,10 +83,10 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
const files = await getPromisedFiles(note.fileIds);
const text = note.text;
let poll: Poll | undefined;
let poll: Poll | null;
if (note.hasPoll) {
poll = await Polls.findOne({ noteId: note.id });
poll = await Polls.findOneBy({ noteId: note.id });
}
let apText = text;
@ -156,9 +156,9 @@ export async function getEmojis(names: string[]): Promise<Emoji[]> {
if (names == null || names.length === 0) return [];
const emojis = await Promise.all(
names.map(name => Emojis.findOne({
names.map(name => Emojis.findOneBy({
name,
host: null,
host: IsNull(),
}))
);

View File

@ -17,9 +17,9 @@ export async function renderPerson(user: ILocalUser) {
const isSystem = !!user.username.match(/\./);
const [avatar, banner, profile] = await Promise.all([
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined),
UserProfiles.findOneOrFail(user.id),
user.avatarId ? DriveFiles.findOneBy({ id: user.avatarId }) : Promise.resolve(undefined),
user.bannerId ? DriveFiles.findOneBy({ id: user.bannerId }) : Promise.resolve(undefined),
UserProfiles.findOneByOrFail({ userId: user.id }),
]);
const attachment: {