diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-29 21:06:23 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-29 21:06:23 +0900 |
| commit | 108dcb3e611d833e82c2dc3b8f0ccf5552597bc1 (patch) | |
| tree | 29ffd5409c002985cfe0f97ae23664fc23af7bb9 /src/models/note.ts | |
| parent | User blocking (Following part) (#3035) (diff) | |
| download | sharkey-108dcb3e611d833e82c2dc3b8f0ccf5552597bc1.tar.gz sharkey-108dcb3e611d833e82c2dc3b8f0ccf5552597bc1.tar.bz2 sharkey-108dcb3e611d833e82c2dc3b8f0ccf5552597bc1.zip | |
物理削除系の処理を削除
これらの処理はパフォーマンス的に現実的でないし、すべてのモデルの関係を把握している必要があり保守が困難
論理削除でなんとかする
Diffstat (limited to 'src/models/note.ts')
| -rw-r--r-- | src/models/note.ts | 75 |
1 files changed, 3 insertions, 72 deletions
diff --git a/src/models/note.ts b/src/models/note.ts index c147b63f0d..bc1d6b0ec7 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -6,13 +6,10 @@ import isObjectId from '../misc/is-objectid'; import { length } from 'stringz'; import { IUser, pack as packUser } from './user'; import { pack as packApp } from './app'; -import PollVote, { deletePollVote } from './poll-vote'; -import Reaction, { deleteNoteReaction } from './note-reaction'; +import PollVote from './poll-vote'; +import Reaction from './note-reaction'; import { packMany as packFileMany, IDriveFile } from './drive-file'; -import NoteWatching, { deleteNoteWatching } from './note-watching'; -import NoteReaction from './note-reaction'; -import Favorite, { deleteFavorite } from './favorite'; -import Notification, { deleteNotification } from './notification'; +import Favorite from './favorite'; import Following from './following'; import config from '../config'; @@ -108,72 +105,6 @@ export type INote = { _files?: IDriveFile[]; }; -/** - * Noteを物理削除します - */ -export async function deleteNote(note: string | mongo.ObjectID | INote) { - let n: INote; - - // Populate - if (isObjectId(note)) { - n = await Note.findOne({ - _id: note - }); - } else if (typeof note === 'string') { - n = await Note.findOne({ - _id: new mongo.ObjectID(note) - }); - } else { - n = note as INote; - } - - console.log(n == null ? `Note: delete skipped ${note}` : `Note: deleting ${n._id}`); - - if (n == null) return; - - // このNoteへの返信をすべて削除 - await Promise.all(( - await Note.find({ replyId: n._id }) - ).map(x => deleteNote(x))); - - // このNoteのRenoteをすべて削除 - await Promise.all(( - await Note.find({ renoteId: n._id }) - ).map(x => deleteNote(x))); - - // この投稿に対するNoteWatchingをすべて削除 - await Promise.all(( - await NoteWatching.find({ noteId: n._id }) - ).map(x => deleteNoteWatching(x))); - - // この投稿に対するNoteReactionをすべて削除 - await Promise.all(( - await NoteReaction.find({ noteId: n._id }) - ).map(x => deleteNoteReaction(x))); - - // この投稿に対するPollVoteをすべて削除 - await Promise.all(( - await PollVote.find({ noteId: n._id }) - ).map(x => deletePollVote(x))); - - // この投稿に対するFavoriteをすべて削除 - await Promise.all(( - await Favorite.find({ noteId: n._id }) - ).map(x => deleteFavorite(x))); - - // この投稿に対するNotificationをすべて削除 - await Promise.all(( - await Notification.find({ noteId: n._id }) - ).map(x => deleteNotification(x))); - - // このNoteを削除 - await Note.remove({ - _id: n._id - }); - - console.log(`Note: deleted ${n._id}`); -} - export const hideNote = async (packedNote: any, meId: mongo.ObjectID) => { let hide = false; |