summaryrefslogtreecommitdiff
path: root/packages/backend/src/services/chart/charts/classes/per-user-following.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-12-14 18:12:37 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-12-14 18:12:37 +0900
commit0be4e1046239f1ed62bb73d4df51a7b9eb1a135f (patch)
tree5e0c0d37036490e25073e14e2f9520d257eaa6d4 /packages/backend/src/services/chart/charts/classes/per-user-following.ts
parentNew Crowdin updates (#8033) (diff)
downloadmisskey-0be4e1046239f1ed62bb73d4df51a7b9eb1a135f.tar.gz
misskey-0be4e1046239f1ed62bb73d4df51a7b9eb1a135f.tar.bz2
misskey-0be4e1046239f1ed62bb73d4df51a7b9eb1a135f.zip
enhance(backend): improve chart engine
Diffstat (limited to 'packages/backend/src/services/chart/charts/classes/per-user-following.ts')
-rw-r--r--packages/backend/src/services/chart/charts/classes/per-user-following.ts121
1 files changed, 0 insertions, 121 deletions
diff --git a/packages/backend/src/services/chart/charts/classes/per-user-following.ts b/packages/backend/src/services/chart/charts/classes/per-user-following.ts
deleted file mode 100644
index 67b623057d..0000000000
--- a/packages/backend/src/services/chart/charts/classes/per-user-following.ts
+++ /dev/null
@@ -1,121 +0,0 @@
-import autobind from 'autobind-decorator';
-import Chart, { Obj, DeepPartial } from '../../core';
-import { SchemaType } from '@/misc/schema';
-import { Followings, Users } from '@/models/index';
-import { Not, IsNull } from 'typeorm';
-import { User } from '@/models/entities/user';
-import { name, schema } from '../schemas/per-user-following';
-
-type PerUserFollowingLog = SchemaType<typeof schema>;
-
-export default class PerUserFollowingChart extends Chart<PerUserFollowingLog> {
- constructor() {
- super(name, schema, true);
- }
-
- @autobind
- protected genNewLog(latest: PerUserFollowingLog): DeepPartial<PerUserFollowingLog> {
- return {
- local: {
- followings: {
- total: latest.local.followings.total,
- },
- followers: {
- total: latest.local.followers.total,
- },
- },
- remote: {
- followings: {
- total: latest.remote.followings.total,
- },
- followers: {
- total: latest.remote.followers.total,
- },
- },
- };
- }
-
- @autobind
- protected aggregate(logs: PerUserFollowingLog[]): PerUserFollowingLog {
- return {
- local: {
- followings: {
- total: logs[0].local.followings.total,
- inc: logs.reduce((a, b) => a + b.local.followings.inc, 0),
- dec: logs.reduce((a, b) => a + b.local.followings.dec, 0),
- },
- followers: {
- total: logs[0].local.followers.total,
- inc: logs.reduce((a, b) => a + b.local.followers.inc, 0),
- dec: logs.reduce((a, b) => a + b.local.followers.dec, 0),
- },
- },
- remote: {
- followings: {
- total: logs[0].remote.followings.total,
- inc: logs.reduce((a, b) => a + b.remote.followings.inc, 0),
- dec: logs.reduce((a, b) => a + b.remote.followings.dec, 0),
- },
- followers: {
- total: logs[0].remote.followers.total,
- inc: logs.reduce((a, b) => a + b.remote.followers.inc, 0),
- dec: logs.reduce((a, b) => a + b.remote.followers.dec, 0),
- },
- },
- };
- }
-
- @autobind
- protected async fetchActual(group: string): Promise<DeepPartial<PerUserFollowingLog>> {
- const [
- localFollowingsCount,
- localFollowersCount,
- remoteFollowingsCount,
- remoteFollowersCount,
- ] = await Promise.all([
- Followings.count({ followerId: group, followeeHost: null }),
- Followings.count({ followeeId: group, followerHost: null }),
- Followings.count({ followerId: group, followeeHost: Not(IsNull()) }),
- Followings.count({ followeeId: group, followerHost: Not(IsNull()) }),
- ]);
-
- return {
- local: {
- followings: {
- total: localFollowingsCount,
- },
- followers: {
- total: localFollowersCount,
- },
- },
- remote: {
- followings: {
- total: remoteFollowingsCount,
- },
- followers: {
- total: remoteFollowersCount,
- },
- },
- };
- }
-
- @autobind
- public async update(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }, isFollow: boolean) {
- const update: Obj = {};
-
- update.total = isFollow ? 1 : -1;
-
- if (isFollow) {
- update.inc = 1;
- } else {
- update.dec = 1;
- }
-
- this.inc({
- [Users.isLocalUser(follower) ? 'local' : 'remote']: { followings: update },
- }, follower.id);
- this.inc({
- [Users.isLocalUser(followee) ? 'local' : 'remote']: { followers: update },
- }, followee.id);
- }
-}