summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-10-29 21:06:23 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-10-29 21:06:23 +0900
commit108dcb3e611d833e82c2dc3b8f0ccf5552597bc1 (patch)
tree29ffd5409c002985cfe0f97ae23664fc23af7bb9 /src
parentUser blocking (Following part) (#3035) (diff)
downloadsharkey-108dcb3e611d833e82c2dc3b8f0ccf5552597bc1.tar.gz
sharkey-108dcb3e611d833e82c2dc3b8f0ccf5552597bc1.tar.bz2
sharkey-108dcb3e611d833e82c2dc3b8f0ccf5552597bc1.zip
物理削除系の処理を削除
これらの処理はパフォーマンス的に現実的でないし、すべてのモデルの関係を把握している必要があり保守が困難 論理削除でなんとかする
Diffstat (limited to 'src')
-rw-r--r--src/models/access-token.ts28
-rw-r--r--src/models/blocking.ts28
-rw-r--r--src/models/drive-file-thumbnail.ts33
-rw-r--r--src/models/drive-file.ts62
-rw-r--r--src/models/drive-folder.ts45
-rw-r--r--src/models/favorite.ts27
-rw-r--r--src/models/follow-request.ts27
-rw-r--r--src/models/following.ts28
-rw-r--r--src/models/messaging-history.ts28
-rw-r--r--src/models/messaging-message.ts33
-rw-r--r--src/models/mute.ts28
-rw-r--r--src/models/note-reaction.ts27
-rw-r--r--src/models/note-watching.ts28
-rw-r--r--src/models/note.ts75
-rw-r--r--src/models/notification.ts27
-rw-r--r--src/models/poll-vote.ts28
-rw-r--r--src/models/sw-subscription.ts28
-rw-r--r--src/models/user-list.ts27
-rw-r--r--src/models/user.ts178
-rw-r--r--src/server/api/endpoints/users/lists/delete.ts6
20 files changed, 12 insertions, 779 deletions
diff --git a/src/models/access-token.ts b/src/models/access-token.ts
index e9cbec7061..66c5c91c0b 100644
--- a/src/models/access-token.ts
+++ b/src/models/access-token.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const AccessToken = db.get<IAccessToken>('accessTokens');
AccessToken.createIndex('token');
@@ -15,30 +14,3 @@ export type IAccessToken = {
token: string;
hash: string;
};
-
-/**
- * AccessTokenを物理削除します
- */
-export async function deleteAccessToken(accessToken: string | mongo.ObjectID | IAccessToken) {
- let a: IAccessToken;
-
- // Populate
- if (isObjectId(accessToken)) {
- a = await AccessToken.findOne({
- _id: accessToken
- });
- } else if (typeof accessToken === 'string') {
- a = await AccessToken.findOne({
- _id: new mongo.ObjectID(accessToken)
- });
- } else {
- a = accessToken as IAccessToken;
- }
-
- if (a == null) return;
-
- // このAccessTokenを削除
- await AccessToken.remove({
- _id: a._id
- });
-}
diff --git a/src/models/blocking.ts b/src/models/blocking.ts
index 9a6e4ce42d..2974b53554 100644
--- a/src/models/blocking.ts
+++ b/src/models/blocking.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const Blocking = db.get<IBlocking>('blocking');
Blocking.createIndex(['blockerId', 'blockeeId'], { unique: true });
@@ -12,30 +11,3 @@ export type IBlocking = {
blockeeId: mongo.ObjectID;
blockerId: mongo.ObjectID;
};
-
-/**
- * Blockingを物理削除します
- */
-export async function deleteBlocking(blocking: string | mongo.ObjectID | IBlocking) {
- let f: IBlocking;
-
- // Populate
- if (isObjectId(blocking)) {
- f = await Blocking.findOne({
- _id: blocking
- });
- } else if (typeof blocking === 'string') {
- f = await Blocking.findOne({
- _id: new mongo.ObjectID(blocking)
- });
- } else {
- f = blocking as IBlocking;
- }
-
- if (f == null) return;
-
- // このBlockingを削除
- await Blocking.remove({
- _id: f._id
- });
-}
diff --git a/src/models/drive-file-thumbnail.ts b/src/models/drive-file-thumbnail.ts
index 5864b8d321..bdb3d010e6 100644
--- a/src/models/drive-file-thumbnail.ts
+++ b/src/models/drive-file-thumbnail.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import monkDb, { nativeDbConn } from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const DriveFileThumbnail = monkDb.get<IDriveFileThumbnail>('driveFileThumbnails.files');
DriveFileThumbnail.createIndex('metadata.originalId', { sparse: true, unique: true });
@@ -28,35 +27,3 @@ export type IDriveFileThumbnail = {
contentType: string;
metadata: IMetadata;
};
-
-/**
- * DriveFileThumbnailを物理削除します
- */
-export async function deleteDriveFileThumbnail(driveFile: string | mongo.ObjectID | IDriveFileThumbnail) {
- let d: IDriveFileThumbnail;
-
- // Populate
- if (isObjectId(driveFile)) {
- d = await DriveFileThumbnail.findOne({
- _id: driveFile
- });
- } else if (typeof driveFile === 'string') {
- d = await DriveFileThumbnail.findOne({
- _id: new mongo.ObjectID(driveFile)
- });
- } else {
- d = driveFile as IDriveFileThumbnail;
- }
-
- if (d == null) return;
-
- // このDriveFileThumbnailのチャンクをすべて削除
- await DriveFileThumbnailChunk.remove({
- files_id: d._id
- });
-
- // このDriveFileThumbnailを削除
- await DriveFileThumbnail.remove({
- _id: d._id
- });
-}
diff --git a/src/models/drive-file.ts b/src/models/drive-file.ts
index c9fdb6156c..ecbf279d03 100644
--- a/src/models/drive-file.ts
+++ b/src/models/drive-file.ts
@@ -4,10 +4,6 @@ import { pack as packFolder } from './drive-folder';
import config from '../config';
import monkDb, { nativeDbConn } from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
-import Note, { deleteNote } from './note';
-import MessagingMessage, { deleteMessagingMessage } from './messaging-message';
-import User from './user';
-import DriveFileThumbnail, { deleteDriveFileThumbnail } from './drive-file-thumbnail';
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
DriveFile.createIndex('md5');
@@ -77,64 +73,6 @@ export function validateFileName(name: string): boolean {
);
}
-/**
- * DriveFileを物理削除します
- */
-export async function deleteDriveFile(driveFile: string | mongo.ObjectID | IDriveFile) {
- let d: IDriveFile;
-
- // Populate
- if (isObjectId(driveFile)) {
- d = await DriveFile.findOne({
- _id: driveFile
- });
- } else if (typeof driveFile === 'string') {
- d = await DriveFile.findOne({
- _id: new mongo.ObjectID(driveFile)
- });
- } else {
- d = driveFile as IDriveFile;
- }
-
- if (d == null) return;
-
- // このDriveFileを添付しているNoteをすべて削除
- await Promise.all((
- await Note.find({ fileIds: d._id })
- ).map(x => deleteNote(x)));
-
- // このDriveFileを添付しているMessagingMessageをすべて削除
- await Promise.all((
- await MessagingMessage.find({ fileId: d._id })
- ).map(x => deleteMessagingMessage(x)));
-
- // このDriveFileがアバターやバナーに使われていたらそれらのプロパティをnullにする
- const u = await User.findOne({ _id: d.metadata.userId });
- if (u) {
- if (u.avatarId && u.avatarId.equals(d._id)) {
- await User.update({ _id: u._id }, { $set: { avatarId: null } });
- }
- if (u.bannerId && u.bannerId.equals(d._id)) {
- await User.update({ _id: u._id }, { $set: { bannerId: null } });
- }
- }
-
- // このDriveFileのDriveFileThumbnailをすべて削除
- await Promise.all((
- await DriveFileThumbnail.find({ 'metadata.originalId': d._id })
- ).map(x => deleteDriveFileThumbnail(x)));
-
- // このDriveFileのチャンクをすべて削除
- await DriveFileChunk.remove({
- files_id: d._id
- });
-
- // このDriveFileを削除
- await DriveFile.remove({
- _id: d._id
- });
-}
-
export const packMany = async (
files: any[],
options?: {
diff --git a/src/models/drive-folder.ts b/src/models/drive-folder.ts
index e826d78403..c95fdeb05d 100644
--- a/src/models/drive-folder.ts
+++ b/src/models/drive-folder.ts
@@ -24,51 +24,6 @@ export function isValidFolderName(name: string): boolean {
}
/**
- * DriveFolderを物理削除します
- */
-export async function deleteDriveFolder(driveFolder: string | mongo.ObjectID | IDriveFolder) {
- let d: IDriveFolder;
-
- // Populate
- if (isObjectId(driveFolder)) {
- d = await DriveFolder.findOne({
- _id: driveFolder
- });
- } else if (typeof driveFolder === 'string') {
- d = await DriveFolder.findOne({
- _id: new mongo.ObjectID(driveFolder)
- });
- } else {
- d = driveFolder as IDriveFolder;
- }
-
- if (d == null) return;
-
- // このDriveFolderに格納されているDriveFileがあればすべてルートに移動
- await DriveFile.update({
- 'metadata.folderId': d._id
- }, {
- $set: {
- 'metadata.folderId': null
- }
- });
-
- // このDriveFolderに格納されているDriveFolderがあればすべてルートに移動
- await DriveFolder.update({
- parentId: d._id
- }, {
- $set: {
- parentId: null
- }
- });
-
- // このDriveFolderを削除
- await DriveFolder.remove({
- _id: d._id
- });
-}
-
-/**
* Pack a drive folder for API response
*/
export const pack = (
diff --git a/src/models/favorite.ts b/src/models/favorite.ts
index 9a01d3a990..1ec923c9eb 100644
--- a/src/models/favorite.ts
+++ b/src/models/favorite.ts
@@ -15,33 +15,6 @@ export type IFavorite = {
noteId: mongo.ObjectID;
};
-/**
- * Favoriteを物理削除します
- */
-export async function deleteFavorite(favorite: string | mongo.ObjectID | IFavorite) {
- let f: IFavorite;
-
- // Populate
- if (isObjectId(favorite)) {
- f = await Favorite.findOne({
- _id: favorite
- });
- } else if (typeof favorite === 'string') {
- f = await Favorite.findOne({
- _id: new mongo.ObjectID(favorite)
- });
- } else {
- f = favorite as IFavorite;
- }
-
- if (f == null) return;
-
- // このFavoriteを削除
- await Favorite.remove({
- _id: f._id
- });
-}
-
export const packMany = async (
favorites: any[],
me: any
diff --git a/src/models/follow-request.ts b/src/models/follow-request.ts
index 01d4b8ce6b..02b2a85b9f 100644
--- a/src/models/follow-request.ts
+++ b/src/models/follow-request.ts
@@ -29,33 +29,6 @@ export type IFollowRequest = {
};
/**
- * FollowRequestを物理削除します
- */
-export async function deleteFollowRequest(followRequest: string | mongo.ObjectID | IFollowRequest) {
- let f: IFollowRequest;
-
- // Populate
- if (isObjectId(followRequest)) {
- f = await FollowRequest.findOne({
- _id: followRequest
- });
- } else if (typeof followRequest === 'string') {
- f = await FollowRequest.findOne({
- _id: new mongo.ObjectID(followRequest)
- });
- } else {
- f = followRequest as IFollowRequest;
- }
-
- if (f == null) return;
-
- // このFollowingを削除
- await FollowRequest.remove({
- _id: f._id
- });
-}
-
-/**
* Pack a request for API response
*/
export const pack = (
diff --git a/src/models/following.ts b/src/models/following.ts
index 2d55ce3616..58ede35a95 100644
--- a/src/models/following.ts
+++ b/src/models/following.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const Following = db.get<IFollowing>('following');
Following.createIndex(['followerId', 'followeeId'], { unique: true });
@@ -25,30 +24,3 @@ export type IFollowing = {
sharedInbox?: string;
}
};
-
-/**
- * Followingを物理削除します
- */
-export async function deleteFollowing(following: string | mongo.ObjectID | IFollowing) {
- let f: IFollowing;
-
- // Populate
- if (isObjectId(following)) {
- f = await Following.findOne({
- _id: following
- });
- } else if (typeof following === 'string') {
- f = await Following.findOne({
- _id: new mongo.ObjectID(following)
- });
- } else {
- f = following as IFollowing;
- }
-
- if (f == null) return;
-
- // このFollowingを削除
- await Following.remove({
- _id: f._id
- });
-}
diff --git a/src/models/messaging-history.ts b/src/models/messaging-history.ts
index 4d7db5617a..6864e22d2f 100644
--- a/src/models/messaging-history.ts
+++ b/src/models/messaging-history.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const MessagingHistory = db.get<IMessagingHistory>('messagingHistories');
export default MessagingHistory;
@@ -12,30 +11,3 @@ export type IMessagingHistory = {
partnerId: mongo.ObjectID;
messageId: mongo.ObjectID;
};
-
-/**
- * MessagingHistoryを物理削除します
- */
-export async function deleteMessagingHistory(messagingHistory: string | mongo.ObjectID | IMessagingHistory) {
- let m: IMessagingHistory;
-
- // Populate
- if (isObjectId(messagingHistory)) {
- m = await MessagingHistory.findOne({
- _id: messagingHistory
- });
- } else if (typeof messagingHistory === 'string') {
- m = await MessagingHistory.findOne({
- _id: new mongo.ObjectID(messagingHistory)
- });
- } else {
- m = messagingHistory as IMessagingHistory;
- }
-
- if (m == null) return;
-
- // このMessagingHistoryを削除
- await MessagingHistory.remove({
- _id: m._id
- });
-}
diff --git a/src/models/messaging-message.ts b/src/models/messaging-message.ts
index 7e94205ca5..4c52ae78ca 100644
--- a/src/models/messaging-message.ts
+++ b/src/models/messaging-message.ts
@@ -4,7 +4,6 @@ import { pack as packUser } from './user';
import { pack as packFile } from './drive-file';
import db from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
-import MessagingHistory, { deleteMessagingHistory } from './messaging-history';
import { length } from 'stringz';
const MessagingMessage = db.get<IMessagingMessage>('messagingMessages');
@@ -25,38 +24,6 @@ export function isValidText(text: string): boolean {
}
/**
- * MessagingMessageを物理削除します
- */
-export async function deleteMessagingMessage(messagingMessage: string | mongo.ObjectID | IMessagingMessage) {
- let m: IMessagingMessage;
-
- // Populate
- if (isObjectId(messagingMessage)) {
- m = await MessagingMessage.findOne({
- _id: messagingMessage
- });
- } else if (typeof messagingMessage === 'string') {
- m = await MessagingMessage.findOne({
- _id: new mongo.ObjectID(messagingMessage)
- });
- } else {
- m = messagingMessage as IMessagingMessage;
- }
-
- if (m == null) return;
-
- // このMessagingMessageを指すMessagingHistoryをすべて削除
- await Promise.all((
- await MessagingHistory.find({ messageId: m._id })
- ).map(x => deleteMessagingHistory(x)));
-
- // このMessagingMessageを削除
- await MessagingMessage.remove({
- _id: m._id
- });
-}
-
-/**
* Pack a messaging message for API response
*/
export const pack = (
diff --git a/src/models/mute.ts b/src/models/mute.ts
index adcaf04b36..4bad3d3d31 100644
--- a/src/models/mute.ts
+++ b/src/models/mute.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const Mute = db.get<IMute>('mute');
Mute.createIndex(['muterId', 'muteeId'], { unique: true });
@@ -12,30 +11,3 @@ export interface IMute {
muterId: mongo.ObjectID;
muteeId: mongo.ObjectID;
}
-
-/**
- * Muteを物理削除します
- */
-export async function deleteMute(mute: string | mongo.ObjectID | IMute) {
- let m: IMute;
-
- // Populate
- if (isObjectId(mute)) {
- m = await Mute.findOne({
- _id: mute
- });
- } else if (typeof mute === 'string') {
- m = await Mute.findOne({
- _id: new mongo.ObjectID(mute)
- });
- } else {
- m = mute as IMute;
- }
-
- if (m == null) return;
-
- // このMuteを削除
- await Mute.remove({
- _id: m._id
- });
-}
diff --git a/src/models/note-reaction.ts b/src/models/note-reaction.ts
index 0df9b921a5..256ed8203f 100644
--- a/src/models/note-reaction.ts
+++ b/src/models/note-reaction.ts
@@ -34,33 +34,6 @@ export const validateReaction = $.str.or([
]);
/**
- * NoteReactionを物理削除します
- */
-export async function deleteNoteReaction(noteReaction: string | mongo.ObjectID | INoteReaction) {
- let n: INoteReaction;
-
- // Populate
- if (isObjectId(noteReaction)) {
- n = await NoteReaction.findOne({
- _id: noteReaction
- });
- } else if (typeof noteReaction === 'string') {
- n = await NoteReaction.findOne({
- _id: new mongo.ObjectID(noteReaction)
- });
- } else {
- n = noteReaction as INoteReaction;
- }
-
- if (n == null) return;
-
- // このNoteReactionを削除
- await NoteReaction.remove({
- _id: n._id
- });
-}
-
-/**
* Pack a reaction for API response
*/
export const pack = (
diff --git a/src/models/note-watching.ts b/src/models/note-watching.ts
index ae576907bc..b5ef3b61b7 100644
--- a/src/models/note-watching.ts
+++ b/src/models/note-watching.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const NoteWatching = db.get<INoteWatching>('noteWatching');
NoteWatching.createIndex(['userId', 'noteId'], { unique: true });
@@ -12,30 +11,3 @@ export interface INoteWatching {
userId: mongo.ObjectID;
noteId: mongo.ObjectID;
}
-
-/**
- * NoteWatchingを物理削除します
- */
-export async function deleteNoteWatching(noteWatching: string | mongo.ObjectID | INoteWatching) {
- let n: INoteWatching;
-
- // Populate
- if (isObjectId(noteWatching)) {
- n = await NoteWatching.findOne({
- _id: noteWatching
- });
- } else if (typeof noteWatching === 'string') {
- n = await NoteWatching.findOne({
- _id: new mongo.ObjectID(noteWatching)
- });
- } else {
- n = noteWatching as INoteWatching;
- }
-
- if (n == null) return;
-
- // このNoteWatchingを削除
- await NoteWatching.remove({
- _id: n._id
- });
-}
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;
diff --git a/src/models/notification.ts b/src/models/notification.ts
index b385a1ed72..34629ade0c 100644
--- a/src/models/notification.ts
+++ b/src/models/notification.ts
@@ -51,33 +51,6 @@ export interface INotification {
isRead: Boolean;
}
-/**
- * Notificationを物理削除します
- */
-export async function deleteNotification(notification: string | mongo.ObjectID | INotification) {
- let n: INotification;
-
- // Populate
- if (isObjectId(notification)) {
- n = await Notification.findOne({
- _id: notification
- });
- } else if (typeof notification === 'string') {
- n = await Notification.findOne({
- _id: new mongo.ObjectID(notification)
- });
- } else {
- n = notification as INotification;
- }
-
- if (n == null) return;
-
- // このNotificationを削除
- await Notification.remove({
- _id: n._id
- });
-}
-
export const packMany = async (
notifications: any[]
) => {
diff --git a/src/models/poll-vote.ts b/src/models/poll-vote.ts
index f9faa8124d..4d33b100e7 100644
--- a/src/models/poll-vote.ts
+++ b/src/models/poll-vote.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const PollVote = db.get<IPollVote>('pollVotes');
export default PollVote;
@@ -12,30 +11,3 @@ export interface IPollVote {
noteId: mongo.ObjectID;
choice: number;
}
-
-/**
- * PollVoteを物理削除します
- */
-export async function deletePollVote(pollVote: string | mongo.ObjectID | IPollVote) {
- let p: IPollVote;
-
- // Populate
- if (isObjectId(pollVote)) {
- p = await PollVote.findOne({
- _id: pollVote
- });
- } else if (typeof pollVote === 'string') {
- p = await PollVote.findOne({
- _id: new mongo.ObjectID(pollVote)
- });
- } else {
- p = pollVote as IPollVote;
- }
-
- if (p == null) return;
-
- // このPollVoteを削除
- await PollVote.remove({
- _id: p._id
- });
-}
diff --git a/src/models/sw-subscription.ts b/src/models/sw-subscription.ts
index baeccc28d5..743d0d2dd9 100644
--- a/src/models/sw-subscription.ts
+++ b/src/models/sw-subscription.ts
@@ -1,6 +1,5 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
-import isObjectId from '../misc/is-objectid';
const SwSubscription = db.get<ISwSubscription>('swSubscriptions');
export default SwSubscription;
@@ -12,30 +11,3 @@ export interface ISwSubscription {
auth: string;
publickey: string;
}
-
-/**
- * SwSubscriptionを物理削除します
- */
-export async function deleteSwSubscription(swSubscription: string | mongo.ObjectID | ISwSubscription) {
- let s: ISwSubscription;
-
- // Populate
- if (isObjectId(swSubscription)) {
- s = await SwSubscription.findOne({
- _id: swSubscription
- });
- } else if (typeof swSubscription === 'string') {
- s = await SwSubscription.findOne({
- _id: new mongo.ObjectID(swSubscription)
- });
- } else {
- s = swSubscription as ISwSubscription;
- }
-
- if (s == null) return;
-
- // このSwSubscriptionを削除
- await SwSubscription.remove({
- _id: s._id
- });
-}
diff --git a/src/models/user-list.ts b/src/models/user-list.ts
index 9e0be6a944..ae231aff62 100644
--- a/src/models/user-list.ts
+++ b/src/models/user-list.ts
@@ -14,33 +14,6 @@ export interface IUserList {
userIds: mongo.ObjectID[];
}
-/**
- * UserListを物理削除します
- */
-export async function deleteUserList(userList: string | mongo.ObjectID | IUserList) {
- let u: IUserList;
-
- // Populate
- if (isObjectId(userList)) {
- u = await UserList.findOne({
- _id: userList
- });
- } else if (typeof userList === 'string') {
- u = await UserList.findOne({
- _id: new mongo.ObjectID(userList)
- });
- } else {
- u = userList as IUserList;
- }
-
- if (u == null) return;
-
- // このUserListを削除
- await UserList.remove({
- _id: u._id
- });
-}
-
export const pack = (
userList: string | mongo.ObjectID | IUserList
) => new Promise<any>(async (resolve, reject) => {
diff --git a/src/models/user.ts b/src/models/user.ts
index e13802595c..149567dd77 100644
--- a/src/models/user.ts
+++ b/src/models/user.ts
@@ -1,28 +1,15 @@
import * as mongo from 'mongodb';
const deepcopy = require('deepcopy');
-const sequential = require('promise-sequential');
import rap from '@prezzemolo/rap';
import db from '../db/mongodb';
import isObjectId from '../misc/is-objectid';
-import Note, { packMany as packNoteMany, deleteNote } from './note';
-import Following, { deleteFollowing } from './following';
-import Blocking, { deleteBlocking } from './blocking';
-import Mute, { deleteMute } from './mute';
+import { packMany as packNoteMany } from './note';
+import Following from './following';
+import Blocking from './blocking';
+import Mute from './mute';
import { getFriendIds } from '../server/api/common/get-friends';
import config from '../config';
-import AccessToken, { deleteAccessToken } from './access-token';
-import NoteWatching, { deleteNoteWatching } from './note-watching';
-import Favorite, { deleteFavorite } from './favorite';
-import NoteReaction, { deleteNoteReaction } from './note-reaction';
-import MessagingMessage, { deleteMessagingMessage } from './messaging-message';
-import MessagingHistory, { deleteMessagingHistory } from './messaging-history';
-import DriveFile, { deleteDriveFile } from './drive-file';
-import DriveFolder, { deleteDriveFolder } from './drive-folder';
-import PollVote, { deletePollVote } from './poll-vote';
-import SwSubscription, { deleteSwSubscription } from './sw-subscription';
-import Notification, { deleteNotification } from './notification';
-import UserList, { deleteUserList } from './user-list';
-import FollowRequest, { deleteFollowRequest } from './follow-request';
+import FollowRequest from './follow-request';
const User = db.get<IUser>('users');
@@ -169,161 +156,6 @@ export function isValidBirthday(birthday: string): boolean {
//#endregion
/**
- * Userを物理削除します
- */
-export async function deleteUser(user: string | mongo.ObjectID | IUser) {
- let u: IUser;
-
- // Populate
- if (isObjectId(user)) {
- u = await User.findOne({
- _id: user
- });
- } else if (typeof user === 'string') {
- u = await User.findOne({
- _id: new mongo.ObjectID(user)
- });
- } else {
- u = user as IUser;
- }
-
- console.log(u == null ? `User: delete skipped ${user}` : `User: deleting ${u._id}`);
-
- if (u == null) return;
-
- // このユーザーのAccessTokenをすべて削除
- await Promise.all((
- await AccessToken.find({ userId: u._id })
- ).map(x => deleteAccessToken(x)));
-
- // このユーザーのNoteをすべて削除
- await sequential((
- await Note.find({ userId: u._id })
- ).map(x => () => deleteNote(x)));
-
- // このユーザーのNoteReactionをすべて削除
- await Promise.all((
- await NoteReaction.find({ userId: u._id })
- ).map(x => deleteNoteReaction(x)));
-
- // このユーザーのNoteWatchingをすべて削除
- await Promise.all((
- await NoteWatching.find({ userId: u._id })
- ).map(x => deleteNoteWatching(x)));
-
- // このユーザーのPollVoteをすべて削除
- await Promise.all((
- await PollVote.find({ userId: u._id })
- ).map(x => deletePollVote(x)));
-
- // このユーザーのFavoriteをすべて削除
- await Promise.all((
- await Favorite.find({ userId: u._id })
- ).map(x => deleteFavorite(x)));
-
- // このユーザーのMessageをすべて削除
- await Promise.all((
- await MessagingMessage.find({ userId: u._id })
- ).map(x => deleteMessagingMessage(x)));
-
- // このユーザーへのMessageをすべて削除
- await Promise.all((
- await MessagingMessage.find({ recipientId: u._id })
- ).map(x => deleteMessagingMessage(x)));
-
- // このユーザーの関わるMessagingHistoryをすべて削除
- await Promise.all((
- await MessagingHistory.find({ $or: [{ partnerId: u._id }, { userId: u._id }] })
- ).map(x => deleteMessagingHistory(x)));
-
- // このユーザーのDriveFileをすべて削除
- await Promise.all((
- await DriveFile.find({ 'metadata.userId': u._id })
- ).map(x => deleteDriveFile(x)));
-
- // このユーザーのDriveFolderをすべて削除
- await Promise.all((
- await DriveFolder.find({ userId: u._id })
- ).map(x => deleteDriveFolder(x)));
-
- // このユーザーのMuteをすべて削除
- await Promise.all((
- await Mute.find({ muterId: u._id })
- ).map(x => deleteMute(x)));
-
- // このユーザーへのMuteをすべて削除
- await Promise.all((
- await Mute.find({ muteeId: u._id })
- ).map(x => deleteMute(x)));
-
- // このユーザーのFollowingをすべて削除
- await Promise.all((
- await Following.find({ followerId: u._id })
- ).map(x => deleteFollowing(x)));
-
- // このユーザーへのFollowingをすべて削除
- await Promise.all((
- await Following.find({ followeeId: u._id })
- ).map(x => deleteFollowing(x)));
-
- // このユーザーのFollowRequestをすべて削除
- await Promise.all((
- await FollowRequest.find({ followerId: u._id })
- ).map(x => deleteFollowRequest(x)));
-
- // このユーザーへのFollowRequestをすべて削除
- await Promise.all((
- await FollowRequest.find({ followeeId: u._id })
- ).map(x => deleteFollowRequest(x)));
-
- // このユーザーのBlockingをすべて削除
- await Promise.all((
- await Blocking.find({ blockerId: u._id })
- ).map(x => deleteBlocking(x)));
-
- // このユーザーへのBlockingをすべて削除
- await Promise.all((
- await Blocking.find({ blockeeId: u._id })
- ).map(x => deleteBlocking(x)));
-
- // このユーザーのSwSubscriptionをすべて削除
- await Promise.all((
- await SwSubscription.find({ userId: u._id })
- ).map(x => deleteSwSubscription(x)));
-
- // このユーザーのNotificationをすべて削除
- await Promise.all((
- await Notification.find({ notifieeId: u._id })
- ).map(x => deleteNotification(x)));
-
- // このユーザーが原因となったNotificationをすべて削除
- await Promise.all((
- await Notification.find({ notifierId: u._id })
- ).map(x => deleteNotification(x)));
-
- // このユーザーのUserListをすべて削除
- await Promise.all((
- await UserList.find({ userId: u._id })
- ).map(x => deleteUserList(x)));
-
- // このユーザーが入っているすべてのUserListからこのユーザーを削除
- await Promise.all((
- await UserList.find({ userIds: u._id })
- ).map(x =>
- UserList.update({ _id: x._id }, {
- $pull: { userIds: u._id }
- })
- ));
-
- // このユーザーを削除
- await User.remove({
- _id: u._id
- });
-
- console.log(`User: deleted ${u._id}`);
-}
-
-/**
* Pack a user for API response
*
* @param user target
diff --git a/src/server/api/endpoints/users/lists/delete.ts b/src/server/api/endpoints/users/lists/delete.ts
index 906534922e..c56963aab6 100644
--- a/src/server/api/endpoints/users/lists/delete.ts
+++ b/src/server/api/endpoints/users/lists/delete.ts
@@ -1,6 +1,6 @@
import $ from 'cafy';
import ID from '../../../../../misc/cafy-id';
-import UserList, { deleteUserList } from '../../../../../models/user-list';
+import UserList from '../../../../../models/user-list';
import { ILocalUser } from '../../../../../models/user';
import getParams from '../../../get-params';
@@ -37,7 +37,9 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
return rej('list not found');
}
- deleteUserList(userList);
+ await UserList.remove({
+ _id: userList._id
+ });
res();
});