mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-24 05:43:07 +02:00
Clean up
This commit is contained in:
parent
f13faf2243
commit
1bf8cbeb29
8 changed files with 2 additions and 256 deletions
|
@ -1,40 +0,0 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import db from '../db/mongodb';
|
||||
import isObjectId from '../misc/is-objectid';
|
||||
|
||||
const FollowedLog = db.get<IFollowedLog>('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
|
||||
});
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import db from '../db/mongodb';
|
||||
import isObjectId from '../misc/is-objectid';
|
||||
|
||||
const FollowingLog = db.get<IFollowingLog>('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
|
||||
});
|
||||
}
|
|
@ -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 })
|
||||
|
|
|
@ -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));
|
||||
});
|
|
@ -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));
|
||||
});
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }, {
|
||||
|
|
Loading…
Reference in a new issue