Use PostgreSQL instead of MongoDB (#4572)
* wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * ✌️ * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * 🍕 * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * ✌️ * clean up * docs * Update push.ts * wip * Update api.ts * wip * ✌️ * Update make-pagination-query.ts * ✌️ * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * 🎨 * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * ✌️ * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * 🎨 * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * ✌️ * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * 🍣 * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * 🕓 * Fix bug * Add test * Add test * rename * Fix bug
This commit is contained in:
parent
13caf37991
commit
f0a29721c9
592 changed files with 13463 additions and 14147 deletions
35
src/services/chart/charts/classes/active-users.ts
Normal file
35
src/services/chart/charts/classes/active-users.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { User } from '../../../../models/entities/user';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Users } from '../../../../models';
|
||||
import { name, schema } from '../schemas/active-users';
|
||||
|
||||
type ActiveUsersLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class ActiveUsersChart extends Chart<ActiveUsersLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: ActiveUsersLog): DeepPartial<ActiveUsersLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<ActiveUsersLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: User) {
|
||||
const update: Obj = {
|
||||
count: 1
|
||||
};
|
||||
|
||||
await this.incIfUnique({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: update
|
||||
}, 'users', user.id);
|
||||
}
|
||||
}
|
||||
69
src/services/chart/charts/classes/drive.ts
Normal file
69
src/services/chart/charts/classes/drive.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { DriveFiles } from '../../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { DriveFile } from '../../../../models/entities/drive-file';
|
||||
import { name, schema } from '../schemas/drive';
|
||||
|
||||
type DriveLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class DriveChart extends Chart<DriveLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: DriveLog): DeepPartial<DriveLog> {
|
||||
return {
|
||||
local: {
|
||||
totalCount: latest.local.totalCount,
|
||||
totalSize: latest.local.totalSize,
|
||||
},
|
||||
remote: {
|
||||
totalCount: latest.remote.totalCount,
|
||||
totalSize: latest.remote.totalSize,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<DriveLog>> {
|
||||
const [localCount, remoteCount, localSize, remoteSize] = await Promise.all([
|
||||
DriveFiles.count({ userHost: null }),
|
||||
DriveFiles.count({ userHost: Not(null) }),
|
||||
DriveFiles.clacDriveUsageOfLocal(),
|
||||
DriveFiles.clacDriveUsageOfRemote()
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
totalCount: localCount,
|
||||
totalSize: localSize,
|
||||
},
|
||||
remote: {
|
||||
totalCount: remoteCount,
|
||||
totalSize: remoteSize,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(file: DriveFile, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.totalCount = isAdditional ? 1 : -1;
|
||||
update.totalSize = isAdditional ? file.size : -file.size;
|
||||
if (isAdditional) {
|
||||
update.incCount = 1;
|
||||
update.incSize = file.size;
|
||||
} else {
|
||||
update.decCount = 1;
|
||||
update.decSize = file.size;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
[file.userHost === null ? 'local' : 'remote']: update
|
||||
});
|
||||
}
|
||||
}
|
||||
51
src/services/chart/charts/classes/federation.ts
Normal file
51
src/services/chart/charts/classes/federation.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Instances } from '../../../../models';
|
||||
import { name, schema } from '../schemas/federation';
|
||||
|
||||
type FederationLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class FederationChart extends Chart<FederationLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: FederationLog): DeepPartial<FederationLog> {
|
||||
return {
|
||||
instance: {
|
||||
total: latest.instance.total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<FederationLog>> {
|
||||
const [total] = await Promise.all([
|
||||
Instances.count({})
|
||||
]);
|
||||
|
||||
return {
|
||||
instance: {
|
||||
total: total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
instance: update
|
||||
});
|
||||
}
|
||||
}
|
||||
35
src/services/chart/charts/classes/hashtag.ts
Normal file
35
src/services/chart/charts/classes/hashtag.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { User } from '../../../../models/entities/user';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Users } from '../../../../models';
|
||||
import { name, schema } from '../schemas/hashtag';
|
||||
|
||||
type HashtagLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class HashtagChart extends Chart<HashtagLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: HashtagLog): DeepPartial<HashtagLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<HashtagLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(hashtag: string, user: User) {
|
||||
const update: Obj = {
|
||||
count: 1
|
||||
};
|
||||
|
||||
await this.incIfUnique({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: update
|
||||
}, 'users', user.id, hashtag);
|
||||
}
|
||||
}
|
||||
160
src/services/chart/charts/classes/instance.ts
Normal file
160
src/services/chart/charts/classes/instance.ts
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { DriveFiles, Followings, Users, Notes } from '../../../../models';
|
||||
import { DriveFile } from '../../../../models/entities/drive-file';
|
||||
import { name, schema } from '../schemas/instance';
|
||||
|
||||
type InstanceLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class InstanceChart extends Chart<InstanceLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: InstanceLog): DeepPartial<InstanceLog> {
|
||||
return {
|
||||
notes: {
|
||||
total: latest.notes.total,
|
||||
},
|
||||
users: {
|
||||
total: latest.users.total,
|
||||
},
|
||||
following: {
|
||||
total: latest.following.total,
|
||||
},
|
||||
followers: {
|
||||
total: latest.followers.total,
|
||||
},
|
||||
drive: {
|
||||
totalFiles: latest.drive.totalFiles,
|
||||
totalUsage: latest.drive.totalUsage,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<InstanceLog>> {
|
||||
const [
|
||||
notesCount,
|
||||
usersCount,
|
||||
followingCount,
|
||||
followersCount,
|
||||
driveFiles,
|
||||
driveUsage,
|
||||
] = await Promise.all([
|
||||
Notes.count({ userHost: group }),
|
||||
Users.count({ host: group }),
|
||||
Followings.count({ followerHost: group }),
|
||||
Followings.count({ followeeHost: group }),
|
||||
DriveFiles.count({ userHost: group }),
|
||||
DriveFiles.clacDriveUsageOfHost(group),
|
||||
]);
|
||||
|
||||
return {
|
||||
notes: {
|
||||
total: notesCount,
|
||||
},
|
||||
users: {
|
||||
total: usersCount,
|
||||
},
|
||||
following: {
|
||||
total: followingCount,
|
||||
},
|
||||
followers: {
|
||||
total: followersCount,
|
||||
},
|
||||
drive: {
|
||||
totalFiles: driveFiles,
|
||||
totalUsage: driveUsage,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async requestReceived(host: string) {
|
||||
await this.inc({
|
||||
requests: {
|
||||
received: 1
|
||||
}
|
||||
}, host);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async requestSent(host: string, isSucceeded: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
if (isSucceeded) {
|
||||
update.succeeded = 1;
|
||||
} else {
|
||||
update.failed = 1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
requests: update
|
||||
}, host);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async newUser(host: string) {
|
||||
await this.inc({
|
||||
users: {
|
||||
total: 1,
|
||||
inc: 1
|
||||
}
|
||||
}, host);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateNote(host: string, isAdditional: boolean) {
|
||||
await this.inc({
|
||||
notes: {
|
||||
total: isAdditional ? 1 : -1,
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
}
|
||||
}, host);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateFollowing(host: string, isAdditional: boolean) {
|
||||
await this.inc({
|
||||
following: {
|
||||
total: isAdditional ? 1 : -1,
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
}
|
||||
}, host);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateFollowers(host: string, isAdditional: boolean) {
|
||||
await this.inc({
|
||||
followers: {
|
||||
total: isAdditional ? 1 : -1,
|
||||
inc: isAdditional ? 1 : 0,
|
||||
dec: isAdditional ? 0 : 1,
|
||||
}
|
||||
}, host);
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async updateDrive(file: DriveFile, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.totalFiles = isAdditional ? 1 : -1;
|
||||
update.totalUsage = isAdditional ? file.size : -file.size;
|
||||
if (isAdditional) {
|
||||
update.incFiles = 1;
|
||||
update.incUsage = file.size;
|
||||
} else {
|
||||
update.decFiles = 1;
|
||||
update.decUsage = file.size;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
drive: update
|
||||
}, file.userHost);
|
||||
}
|
||||
}
|
||||
34
src/services/chart/charts/classes/network.ts
Normal file
34
src/services/chart/charts/classes/network.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { name, schema } from '../schemas/network';
|
||||
|
||||
type NetworkLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class NetworkChart extends Chart<NetworkLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: NetworkLog): DeepPartial<NetworkLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<NetworkLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(incomingRequests: number, time: number, incomingBytes: number, outgoingBytes: number) {
|
||||
const inc: DeepPartial<NetworkLog> = {
|
||||
incomingRequests: incomingRequests,
|
||||
totalTime: time,
|
||||
incomingBytes: incomingBytes,
|
||||
outgoingBytes: outgoingBytes
|
||||
};
|
||||
|
||||
await this.inc(inc);
|
||||
}
|
||||
}
|
||||
71
src/services/chart/charts/classes/notes.ts
Normal file
71
src/services/chart/charts/classes/notes.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Notes } from '../../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { Note } from '../../../../models/entities/note';
|
||||
import { name, schema } from '../schemas/notes';
|
||||
|
||||
type NotesLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class NotesChart extends Chart<NotesLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: NotesLog): DeepPartial<NotesLog> {
|
||||
return {
|
||||
local: {
|
||||
total: latest.local.total,
|
||||
},
|
||||
remote: {
|
||||
total: latest.remote.total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<NotesLog>> {
|
||||
const [localCount, remoteCount] = await Promise.all([
|
||||
Notes.count({ userHost: null }),
|
||||
Notes.count({ userHost: Not(null) })
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
total: localCount,
|
||||
},
|
||||
remote: {
|
||||
total: remoteCount,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(note: Note, isAdditional: boolean) {
|
||||
const update: Obj = {
|
||||
diffs: {}
|
||||
};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
if (note.replyId != null) {
|
||||
update.diffs.reply = isAdditional ? 1 : -1;
|
||||
} else if (note.renoteId != null) {
|
||||
update.diffs.renote = isAdditional ? 1 : -1;
|
||||
} else {
|
||||
update.diffs.normal = isAdditional ? 1 : -1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
[note.userHost === null ? 'local' : 'remote']: update
|
||||
});
|
||||
}
|
||||
}
|
||||
52
src/services/chart/charts/classes/per-user-drive.ts
Normal file
52
src/services/chart/charts/classes/per-user-drive.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { DriveFiles } from '../../../../models';
|
||||
import { DriveFile } from '../../../../models/entities/drive-file';
|
||||
import { name, schema } from '../schemas/per-user-drive';
|
||||
|
||||
type PerUserDriveLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class PerUserDriveChart extends Chart<PerUserDriveLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: PerUserDriveLog): DeepPartial<PerUserDriveLog> {
|
||||
return {
|
||||
totalCount: latest.totalCount,
|
||||
totalSize: latest.totalSize,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<PerUserDriveLog>> {
|
||||
const [count, size] = await Promise.all([
|
||||
DriveFiles.count({ userId: group }),
|
||||
DriveFiles.clacDriveUsageOf(group)
|
||||
]);
|
||||
|
||||
return {
|
||||
totalCount: count,
|
||||
totalSize: size,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(file: DriveFile, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.totalCount = isAdditional ? 1 : -1;
|
||||
update.totalSize = isAdditional ? file.size : -file.size;
|
||||
if (isAdditional) {
|
||||
update.incCount = 1;
|
||||
update.incSize = file.size;
|
||||
} else {
|
||||
update.decCount = 1;
|
||||
update.decSize = file.size;
|
||||
}
|
||||
|
||||
await this.inc(update, file.userId);
|
||||
}
|
||||
}
|
||||
91
src/services/chart/charts/classes/per-user-following.ts
Normal file
91
src/services/chart/charts/classes/per-user-following.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Followings, Users } from '../../../../models';
|
||||
import { Not } 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 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(null) }),
|
||||
Followings.count({ followeeId: group, followerHost: Not(null) })
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
followings: {
|
||||
total: localFollowingsCount,
|
||||
},
|
||||
followers: {
|
||||
total: localFollowersCount,
|
||||
}
|
||||
},
|
||||
remote: {
|
||||
followings: {
|
||||
total: remoteFollowingsCount,
|
||||
},
|
||||
followers: {
|
||||
total: remoteFollowersCount,
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(follower: User, followee: User, 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);
|
||||
}
|
||||
}
|
||||
58
src/services/chart/charts/classes/per-user-notes.ts
Normal file
58
src/services/chart/charts/classes/per-user-notes.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { User } from '../../../../models/entities/user';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Notes } from '../../../../models';
|
||||
import { Note } from '../../../../models/entities/note';
|
||||
import { name, schema } from '../schemas/per-user-notes';
|
||||
|
||||
type PerUserNotesLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class PerUserNotesChart extends Chart<PerUserNotesLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: PerUserNotesLog): DeepPartial<PerUserNotesLog> {
|
||||
return {
|
||||
total: latest.total,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<PerUserNotesLog>> {
|
||||
const [count] = await Promise.all([
|
||||
Notes.count({ userId: group }),
|
||||
]);
|
||||
|
||||
return {
|
||||
total: count,
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: User, note: Note, isAdditional: boolean) {
|
||||
const update: Obj = {
|
||||
diffs: {}
|
||||
};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
if (note.replyId != null) {
|
||||
update.diffs.reply = isAdditional ? 1 : -1;
|
||||
} else if (note.renoteId != null) {
|
||||
update.diffs.renote = isAdditional ? 1 : -1;
|
||||
} else {
|
||||
update.diffs.normal = isAdditional ? 1 : -1;
|
||||
}
|
||||
|
||||
await this.inc(update, user.id);
|
||||
}
|
||||
}
|
||||
32
src/services/chart/charts/classes/per-user-reactions.ts
Normal file
32
src/services/chart/charts/classes/per-user-reactions.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { DeepPartial } from '../../core';
|
||||
import { User } from '../../../../models/entities/user';
|
||||
import { Note } from '../../../../models/entities/note';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Users } from '../../../../models';
|
||||
import { name, schema } from '../schemas/per-user-reactions';
|
||||
|
||||
type PerUserReactionsLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class PerUserReactionsChart extends Chart<PerUserReactionsLog> {
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: PerUserReactionsLog): DeepPartial<PerUserReactionsLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<PerUserReactionsLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: User, note: Note) {
|
||||
this.inc({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: { count: 1 }
|
||||
}, note.userId);
|
||||
}
|
||||
}
|
||||
47
src/services/chart/charts/classes/test-grouped.ts
Normal file
47
src/services/chart/charts/classes/test-grouped.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { name, schema } from '../schemas/test-grouped';
|
||||
|
||||
type TestGroupedLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class TestGroupedChart extends Chart<TestGroupedLog> {
|
||||
private total = {} as Record<string, number>;
|
||||
|
||||
constructor() {
|
||||
super(name, schema, true);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestGroupedLog): DeepPartial<TestGroupedLog> {
|
||||
return {
|
||||
foo: {
|
||||
total: latest.foo.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(group: string): Promise<DeepPartial<TestGroupedLog>> {
|
||||
return {
|
||||
foo: {
|
||||
total: this.total[group],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment(group: string) {
|
||||
if (this.total[group] == null) this.total[group] = 0;
|
||||
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = 1;
|
||||
update.inc = 1;
|
||||
this.total[group]++;
|
||||
|
||||
await this.inc({
|
||||
foo: update
|
||||
}, group);
|
||||
}
|
||||
}
|
||||
29
src/services/chart/charts/classes/test-unique.ts
Normal file
29
src/services/chart/charts/classes/test-unique.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { name, schema } from '../schemas/test-unique';
|
||||
|
||||
type TestUniqueLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class TestUniqueChart extends Chart<TestUniqueLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestUniqueLog): DeepPartial<TestUniqueLog> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<TestUniqueLog>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async uniqueIncrement(key: string) {
|
||||
await this.incIfUnique({
|
||||
foo: 1
|
||||
}, 'foos', key);
|
||||
}
|
||||
}
|
||||
45
src/services/chart/charts/classes/test.ts
Normal file
45
src/services/chart/charts/classes/test.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { name, schema } from '../schemas/test';
|
||||
|
||||
type TestLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class TestChart extends Chart<TestLog> {
|
||||
private total = 0;
|
||||
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestLog): DeepPartial<TestLog> {
|
||||
return {
|
||||
foo: {
|
||||
total: latest.foo.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<TestLog>> {
|
||||
return {
|
||||
foo: {
|
||||
total: this.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment() {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = 1;
|
||||
update.inc = 1;
|
||||
this.total++;
|
||||
|
||||
await this.inc({
|
||||
foo: update
|
||||
});
|
||||
}
|
||||
}
|
||||
60
src/services/chart/charts/classes/users.ts
Normal file
60
src/services/chart/charts/classes/users.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '../../../../misc/schema';
|
||||
import { Users } from '../../../../models';
|
||||
import { Not } from 'typeorm';
|
||||
import { User } from '../../../../models/entities/user';
|
||||
import { name, schema } from '../schemas/users';
|
||||
|
||||
type UsersLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class UsersChart extends Chart<UsersLog> {
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: UsersLog): DeepPartial<UsersLog> {
|
||||
return {
|
||||
local: {
|
||||
total: latest.local.total,
|
||||
},
|
||||
remote: {
|
||||
total: latest.remote.total,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<UsersLog>> {
|
||||
const [localCount, remoteCount] = await Promise.all([
|
||||
Users.count({ host: null }),
|
||||
Users.count({ host: Not(null) })
|
||||
]);
|
||||
|
||||
return {
|
||||
local: {
|
||||
total: localCount,
|
||||
},
|
||||
remote: {
|
||||
total: remoteCount,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async update(user: User, isAdditional: boolean) {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = isAdditional ? 1 : -1;
|
||||
if (isAdditional) {
|
||||
update.inc = 1;
|
||||
} else {
|
||||
update.dec = 1;
|
||||
}
|
||||
|
||||
await this.inc({
|
||||
[Users.isLocalUser(user) ? 'local' : 'remote']: update
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue