diff --git a/src/models/followed-log.ts b/src/models/followed-log.ts deleted file mode 100644 index 0c8c15f118..0000000000 --- a/src/models/followed-log.ts +++ /dev/null @@ -1,40 +0,0 @@ -import * as mongo from 'mongodb'; -import db from '../db/mongodb'; -import isObjectId from '../misc/is-objectid'; - -const FollowedLog = db.get('followedLogs'); -export default FollowedLog; - -export type IFollowedLog = { - _id: mongo.ObjectID; - createdAt: Date; - userId: mongo.ObjectID; - count: number; -}; - -/** - * FollowedLogを物理削除します - */ -export async function deleteFollowedLog(followedLog: string | mongo.ObjectID | IFollowedLog) { - let f: IFollowedLog; - - // Populate - if (isObjectId(followedLog)) { - f = await FollowedLog.findOne({ - _id: followedLog - }); - } else if (typeof followedLog === 'string') { - f = await FollowedLog.findOne({ - _id: new mongo.ObjectID(followedLog) - }); - } else { - f = followedLog as IFollowedLog; - } - - if (f == null) return; - - // このFollowedLogを削除 - await FollowedLog.remove({ - _id: f._id - }); -} diff --git a/src/models/following-log.ts b/src/models/following-log.ts deleted file mode 100644 index d2efb45b3d..0000000000 --- a/src/models/following-log.ts +++ /dev/null @@ -1,40 +0,0 @@ -import * as mongo from 'mongodb'; -import db from '../db/mongodb'; -import isObjectId from '../misc/is-objectid'; - -const FollowingLog = db.get('followingLogs'); -export default FollowingLog; - -export type IFollowingLog = { - _id: mongo.ObjectID; - createdAt: Date; - userId: mongo.ObjectID; - count: number; -}; - -/** - * FollowingLogを物理削除します - */ -export async function deleteFollowingLog(followingLog: string | mongo.ObjectID | IFollowingLog) { - let f: IFollowingLog; - - // Populate - if (isObjectId(followingLog)) { - f = await FollowingLog.findOne({ - _id: followingLog - }); - } else if (typeof followingLog === 'string') { - f = await FollowingLog.findOne({ - _id: new mongo.ObjectID(followingLog) - }); - } else { - f = followingLog as IFollowingLog; - } - - if (f == null) return; - - // このFollowingLogを削除 - await FollowingLog.remove({ - _id: f._id - }); -} diff --git a/src/models/user.ts b/src/models/user.ts index f2afe00d15..25c4a9eb0f 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -18,8 +18,6 @@ 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 FollowingLog, { deleteFollowingLog } from './following-log'; -import FollowedLog, { deleteFollowedLog } from './followed-log'; import SwSubscription, { deleteSwSubscription } from './sw-subscription'; import Notification, { deleteNotification } from './notification'; import UserList, { deleteUserList } from './user-list'; @@ -277,16 +275,6 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) { await FollowRequest.find({ followeeId: u._id }) ).map(x => deleteFollowRequest(x))); - // このユーザーのFollowingLogをすべて削除 - await Promise.all(( - await FollowingLog.find({ userId: u._id }) - ).map(x => deleteFollowingLog(x))); - - // このユーザーのFollowedLogをすべて削除 - await Promise.all(( - await FollowedLog.find({ userId: u._id }) - ).map(x => deleteFollowedLog(x))); - // このユーザーのSwSubscriptionをすべて削除 await Promise.all(( await SwSubscription.find({ userId: u._id }) diff --git a/src/server/api/endpoints/aggregation/users/followers.ts b/src/server/api/endpoints/aggregation/users/followers.ts deleted file mode 100644 index 94eb83febc..0000000000 --- a/src/server/api/endpoints/aggregation/users/followers.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../../misc/cafy-id'; -import User from '../../../../../models/user'; -import FollowedLog from '../../../../../models/followed-log'; - -/** - * Aggregate followers of a user - */ -export default (params: any) => new Promise(async (res, rej) => { - // Get 'userId' parameter - const [userId, userIdErr] = $.type(ID).get(params.userId); - if (userIdErr) return rej('invalid userId param'); - - // Lookup user - const user = await User.findOne({ - _id: userId - }, { - fields: { - _id: true - } - }); - - if (user === null) { - return rej('user not found'); - } - - const today = new Date(); - const graph = []; - - today.setMinutes(0); - today.setSeconds(0); - today.setMilliseconds(0); - - let cursorDate = new Date(today.getTime()); - let cursorTime = cursorDate.setDate(new Date(today.getTime()).getDate() + 1); - - for (let i = 0; i < 30; i++) { - graph.push(FollowedLog.findOne({ - createdAt: { $lt: new Date(cursorTime / 1000) }, - userId: user._id - }, { - sort: { createdAt: -1 }, - }).then(log => { - cursorDate = new Date(today.getTime()); - cursorTime = cursorDate.setDate(today.getDate() - i); - - return { - date: { - year: cursorDate.getFullYear(), - month: cursorDate.getMonth() + 1, // In JavaScript, month is zero-based. - day: cursorDate.getDate() - }, - count: log ? log.count : 0 - }; - })); - } - - res(await Promise.all(graph)); -}); diff --git a/src/server/api/endpoints/aggregation/users/following.ts b/src/server/api/endpoints/aggregation/users/following.ts deleted file mode 100644 index d2e4d256fe..0000000000 --- a/src/server/api/endpoints/aggregation/users/following.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../../misc/cafy-id'; -import User from '../../../../../models/user'; -import FollowingLog from '../../../../../models/following-log'; - -/** - * Aggregate following of a user - */ -export default (params: any) => new Promise(async (res, rej) => { - // Get 'userId' parameter - const [userId, userIdErr] = $.type(ID).get(params.userId); - if (userIdErr) return rej('invalid userId param'); - - // Lookup user - const user = await User.findOne({ - _id: userId - }, { - fields: { - _id: true - } - }); - - if (user === null) { - return rej('user not found'); - } - - const today = new Date(); - const graph = []; - - today.setMinutes(0); - today.setSeconds(0); - today.setMilliseconds(0); - - let cursorDate = new Date(today.getTime()); - let cursorTime = cursorDate.setDate(new Date(today.getTime()).getDate() + 1); - - for (let i = 0; i < 30; i++) { - graph.push(FollowingLog.findOne({ - createdAt: { $lt: new Date(cursorTime / 1000) }, - userId: user._id - }, { - sort: { createdAt: -1 }, - }).then(log => { - cursorDate = new Date(today.getTime()); - cursorTime = cursorDate.setDate(today.getDate() - i); - - return { - date: { - year: cursorDate.getFullYear(), - month: cursorDate.getMonth() + 1, // In JavaScript, month is zero-based. - day: cursorDate.getDate() - }, - count: log ? log.count : 0 - }; - })); - } - - res(await Promise.all(graph)); -}); diff --git a/src/services/following/create.ts b/src/services/following/create.ts index 1768083d16..c0d0b92154 100644 --- a/src/services/following/create.ts +++ b/src/services/following/create.ts @@ -1,7 +1,5 @@ import User, { isLocalUser, isRemoteUser, pack as packUser, IUser } from '../../models/user'; import Following from '../../models/following'; -import FollowingLog from '../../models/following-log'; -import FollowedLog from '../../models/followed-log'; import { publishMainStream } from '../../stream'; import notify from '../../notify'; import pack from '../../remote/activitypub/renderer'; @@ -20,7 +18,7 @@ export default async function(follower: IUser, followee: IUser, requestId?: stri return; } - const following = await Following.insert({ + await Following.insert({ createdAt: new Date(), followerId: follower._id, followeeId: followee._id, @@ -44,12 +42,6 @@ export default async function(follower: IUser, followee: IUser, requestId?: stri followingCount: 1 } }); - - FollowingLog.insert({ - createdAt: following.createdAt, - userId: follower._id, - count: follower.followingCount + 1 - }); //#endregion //#region Increment followers count @@ -58,11 +50,6 @@ export default async function(follower: IUser, followee: IUser, requestId?: stri followersCount: 1 } }); - FollowedLog.insert({ - createdAt: following.createdAt, - userId: followee._id, - count: followee.followersCount + 1 - }); //#endregion // Publish follow event diff --git a/src/services/following/delete.ts b/src/services/following/delete.ts index 2a67acbf05..3fb0e50b13 100644 --- a/src/services/following/delete.ts +++ b/src/services/following/delete.ts @@ -1,7 +1,5 @@ import User, { isLocalUser, isRemoteUser, pack as packUser, IUser } from '../../models/user'; import Following from '../../models/following'; -import FollowingLog from '../../models/following-log'; -import FollowedLog from '../../models/followed-log'; import { publishMainStream } from '../../stream'; import pack from '../../remote/activitypub/renderer'; import renderFollow from '../../remote/activitypub/renderer/follow'; @@ -29,12 +27,6 @@ export default async function(follower: IUser, followee: IUser) { followingCount: -1 } }); - - FollowingLog.insert({ - createdAt: following.createdAt, - userId: follower._id, - count: follower.followingCount - 1 - }); //#endregion //#region Decrement followers count @@ -43,11 +35,6 @@ export default async function(follower: IUser, followee: IUser) { followersCount: -1 } }); - FollowedLog.insert({ - createdAt: following.createdAt, - userId: followee._id, - count: followee.followersCount - 1 - }); //#endregion // Publish unfollow event diff --git a/src/services/following/requests/accept.ts b/src/services/following/requests/accept.ts index 2a32db6a4d..1f07df29d8 100644 --- a/src/services/following/requests/accept.ts +++ b/src/services/following/requests/accept.ts @@ -5,12 +5,10 @@ import renderFollow from '../../../remote/activitypub/renderer/follow'; import renderAccept from '../../../remote/activitypub/renderer/accept'; import { deliver } from '../../../queue'; import Following from '../../../models/following'; -import FollowingLog from '../../../models/following-log'; -import FollowedLog from '../../../models/followed-log'; import { publishMainStream } from '../../../stream'; export default async function(followee: IUser, follower: IUser) { - const following = await Following.insert({ + await Following.insert({ createdAt: new Date(), followerId: follower._id, followeeId: followee._id, @@ -49,12 +47,6 @@ export default async function(followee: IUser, follower: IUser) { followingCount: 1 } }); - - FollowingLog.insert({ - createdAt: following.createdAt, - userId: follower._id, - count: follower.followingCount + 1 - }); //#endregion //#region Increment followers count @@ -63,12 +55,6 @@ export default async function(followee: IUser, follower: IUser) { followersCount: 1 } }); - - FollowedLog.insert({ - createdAt: following.createdAt, - userId: followee._id, - count: followee.followersCount + 1 - }); //#endregion await User.update({ _id: followee._id }, {