Improve chart engine (#8253)

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update core.ts

* wip

* wip

* #7361

* delete network chart

* federationChart強化 apRequestChart追加

* tweak
This commit is contained in:
syuilo
2022-02-06 00:13:52 +09:00
committed by GitHub
parent 0b462feff6
commit c1b264e4e9
65 changed files with 1616 additions and 1756 deletions

View File

@@ -1,51 +1,28 @@
import autobind from 'autobind-decorator';
import Chart, { Obj, DeepPartial } from '../core';
import Chart, { KVs } from '../core';
import { User } from '@/models/entities/user';
import { SchemaType } from '@/misc/schema';
import { Users } from '@/models/index';
import { name, schema } from './entities/active-users';
type ActiveUsersLog = SchemaType<typeof schema>;
/**
* アクティブユーザーに関するチャート
*/
// eslint-disable-next-line import/no-default-export
export default class ActiveUsersChart extends Chart<ActiveUsersLog> {
export default class ActiveUsersChart extends Chart<typeof schema> {
constructor() {
super(name, schema);
}
@autobind
protected genNewLog(latest: ActiveUsersLog): DeepPartial<ActiveUsersLog> {
return {};
}
@autobind
protected aggregate(logs: ActiveUsersLog[]): ActiveUsersLog {
return {
local: {
users: logs.reduce((a, b) => a.concat(b.local.users), [] as ActiveUsersLog['local']['users']),
},
remote: {
users: logs.reduce((a, b) => a.concat(b.remote.users), [] as ActiveUsersLog['remote']['users']),
},
};
}
@autobind
protected async fetchActual(): Promise<DeepPartial<ActiveUsersLog>> {
protected async queryCurrentState(): Promise<Partial<KVs<typeof schema>>> {
return {};
}
@autobind
public async update(user: { id: User['id'], host: User['host'] }): Promise<void> {
const update: Obj = {
users: [user.id],
};
await this.inc({
[Users.isLocalUser(user) ? 'local' : 'remote']: update,
await this.commit({
'local.users': Users.isLocalUser(user) ? [user.id] : [],
'remote.users': Users.isLocalUser(user) ? [] : [user.id],
});
}
}