summaryrefslogtreecommitdiff
path: root/packages/backend/src/services/note/create.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-03-26 15:34:00 +0900
committerGitHub <noreply@github.com>2022-03-26 15:34:00 +0900
commit1c67c26bd87aae64fe0f2ef45140e12a78564699 (patch)
tree633a3fad1c5841ea20bc39d6b681b455bbdeabf3 /packages/backend/src/services/note/create.ts
parent.js (diff)
downloadmisskey-1c67c26bd87aae64fe0f2ef45140e12a78564699.tar.gz
misskey-1c67c26bd87aae64fe0f2ef45140e12a78564699.tar.bz2
misskey-1c67c26bd87aae64fe0f2ef45140e12a78564699.zip
refactor: migrate to typeorm 3.0 (#8443)
* wip * wip * wip * Update following.ts * wip * wip * wip * Update resolve-user.ts * maxQueryExecutionTime * wip * wip
Diffstat (limited to 'packages/backend/src/services/note/create.ts')
-rw-r--r--packages/backend/src/services/note/create.ts33
1 files changed, 17 insertions, 16 deletions
diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts
index f4b0d52045..2ed194b7e9 100644
--- a/packages/backend/src/services/note/create.ts
+++ b/packages/backend/src/services/note/create.ts
@@ -19,7 +19,7 @@ import { Note, IMentionedRemoteUsers } from '@/models/entities/note.js';
import { Mutings, Users, NoteWatchings, Notes, Instances, UserProfiles, Antennas, Followings, MutedNotes, Channels, ChannelFollowings, Blockings, NoteThreadMutings } from '@/models/index.js';
import { DriveFile } from '@/models/entities/drive-file.js';
import { App } from '@/models/entities/app.js';
-import { Not, getConnection, In } from 'typeorm';
+import { Not, In } from 'typeorm';
import { User, ILocalUser, IRemoteUser } from '@/models/entities/user.js';
import { genId } from '@/misc/gen-id.js';
import { notesChart, perUserNotesChart, activeUsersChart, instanceChart } from '@/services/chart/index.js';
@@ -37,6 +37,7 @@ import { getAntennas } from '@/misc/antenna-cache.js';
import { endedPollNotificationQueue } from '@/queue/queues.js';
import { Cache } from '@/misc/cache.js';
import { UserProfile } from '@/models/entities/user-profile.js';
+import { db } from '@/db/postgre.js';
const mutedWordsCache = new Cache<{ userId: UserProfile['userId']; mutedWords: UserProfile['mutedWords']; }[]>(1000 * 60 * 5);
@@ -78,7 +79,7 @@ class NotificationManager {
public async deliver() {
for (const x of this.queue) {
// ミュート情報を取得
- const mentioneeMutes = await Mutings.find({
+ const mentioneeMutes = await Mutings.findBy({
muterId: x.target,
});
@@ -128,7 +129,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
if (data.reply && data.channel && data.reply.channelId !== data.channel.id) {
if (data.reply.channelId) {
- data.channel = await Channels.findOne(data.reply.channelId);
+ data.channel = await Channels.findOneBy({ id: data.reply.channelId });
} else {
data.channel = null;
}
@@ -137,7 +138,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
// チャンネル内にリプライしたら対象のスコープに合わせる
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
if (data.reply && (data.channel == null) && data.reply.channelId) {
- data.channel = await Channels.findOne(data.reply.channelId);
+ data.channel = await Channels.findOneBy({ id: data.reply.channelId });
}
if (data.createdAt == null) data.createdAt = new Date();
@@ -210,7 +211,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
tags = tags.filter(tag => Array.from(tag || '').length <= 128).splice(0, 32);
if (data.reply && (user.id !== data.reply.userId) && !mentionedUsers.some(u => u.id === data.reply!.userId)) {
- mentionedUsers.push(await Users.findOneOrFail(data.reply!.userId));
+ mentionedUsers.push(await Users.findOneByOrFail({ id: data.reply!.userId }));
}
if (data.visibility === 'specified') {
@@ -223,7 +224,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
}
if (data.reply && !data.visibleUsers.some(x => x.id === data.reply!.userId)) {
- data.visibleUsers.push(await Users.findOneOrFail(data.reply!.userId));
+ data.visibleUsers.push(await Users.findOneByOrFail({ id: data.reply!.userId }));
}
}
@@ -283,7 +284,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
// Channel
if (note.channelId) {
- ChannelFollowings.find({ followeeId: note.channelId }).then(followings => {
+ ChannelFollowings.findBy({ followeeId: note.channelId }).then(followings => {
for (const following of followings) {
insertNoteUnread(following.followerId, note, {
isSpecified: false,
@@ -356,7 +357,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
// 通知
if (data.reply.userHost === null) {
- const threadMuted = await NoteThreadMutings.findOne({
+ const threadMuted = await NoteThreadMutings.findOneBy({
userId: data.reply.userId,
threadId: data.reply.threadId || data.reply.id,
});
@@ -403,13 +404,13 @@ export default async (user: { id: User['id']; username: User['username']; host:
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送
if (data.reply && data.reply.userHost !== null) {
- const u = await Users.findOne(data.reply.userId);
+ const u = await Users.findOneBy({ id: data.reply.userId });
if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u);
}
// 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送
if (data.renote && data.renote.userHost !== null) {
- const u = await Users.findOne(data.renote.userId);
+ const u = await Users.findOneBy({ id: data.renote.userId });
if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u);
}
@@ -434,7 +435,7 @@ export default async (user: { id: User['id']; username: User['username']; host:
lastNotedAt: new Date(),
});
- Notes.count({
+ Notes.countBy({
userId: user.id,
channelId: data.channel.id,
}).then(count => {
@@ -514,7 +515,7 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O
// Append mentions data
if (mentionedUsers.length > 0) {
insert.mentions = mentionedUsers.map(u => u.id);
- const profiles = await UserProfiles.find({ userId: In(insert.mentions) });
+ const profiles = await UserProfiles.findBy({ userId: In(insert.mentions) });
insert.mentionedRemoteUsers = JSON.stringify(mentionedUsers.filter(u => Users.isRemoteUser(u)).map(u => {
const profile = profiles.find(p => p.userId === u.id);
const url = profile != null ? profile.url : null;
@@ -531,7 +532,7 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O
try {
if (insert.hasPoll) {
// Start transaction
- await getConnection().transaction(async transactionalEntityManager => {
+ await db.transaction(async transactionalEntityManager => {
await transactionalEntityManager.insert(Note, insert);
const poll = new Poll({
@@ -581,7 +582,7 @@ function index(note: Note) {
}
async function notifyToWatchersOfRenotee(renote: Note, user: { id: User['id']; }, nm: NotificationManager, type: NotificationType) {
- const watchers = await NoteWatchings.find({
+ const watchers = await NoteWatchings.findBy({
noteId: renote.id,
userId: Not(user.id),
});
@@ -592,7 +593,7 @@ async function notifyToWatchersOfRenotee(renote: Note, user: { id: User['id']; }
}
async function notifyToWatchersOfReplyee(reply: Note, user: { id: User['id']; }, nm: NotificationManager) {
- const watchers = await NoteWatchings.find({
+ const watchers = await NoteWatchings.findBy({
noteId: reply.id,
userId: Not(user.id),
});
@@ -604,7 +605,7 @@ async function notifyToWatchersOfReplyee(reply: Note, user: { id: User['id']; },
async function createMentionedEvents(mentionedUsers: MinimumUser[], note: Note, nm: NotificationManager) {
for (const u of mentionedUsers.filter(u => Users.isLocalUser(u))) {
- const threadMuted = await NoteThreadMutings.findOne({
+ const threadMuted = await NoteThreadMutings.findOneBy({
userId: u.id,
threadId: note.threadId || note.id,
});