diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-24 06:17:55 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-24 06:17:55 +0900 |
| commit | a136715111de5a7822b97d43681d20e494d43505 (patch) | |
| tree | c451210ecaca628d2c7bb953104710f2fa8569ff /src/chart/federation.ts | |
| parent | Make max allowed text length configurable (#2992) (diff) | |
| download | misskey-a136715111de5a7822b97d43681d20e494d43505.tar.gz misskey-a136715111de5a7822b97d43681d20e494d43505.tar.bz2 misskey-a136715111de5a7822b97d43681d20e494d43505.zip | |
Implement #2993
Diffstat (limited to 'src/chart/federation.ts')
| -rw-r--r-- | src/chart/federation.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/chart/federation.ts b/src/chart/federation.ts new file mode 100644 index 0000000000..9d5830a53b --- /dev/null +++ b/src/chart/federation.ts @@ -0,0 +1,65 @@ +import autobind from 'autobind-decorator'; +import Chart, { Obj } from '.'; + +/** + * フェデレーションに関するチャート + */ +type FederationLog = { + instance: { + /** + * インスタンス数の合計 + */ + total: number; + + /** + * 増加インスタンス数 + */ + inc: number; + + /** + * 減少インスタンス数 + */ + dec: number; + }; +}; + +class FederationChart extends Chart<FederationLog> { + constructor() { + super('federation'); + } + + @autobind + protected async getTemplate(init: boolean, latest?: FederationLog): Promise<FederationLog> { + const [total] = init ? await Promise.all([ + Instance.count({}) + ]) : [ + latest ? latest.instance.total : 0 + ]; + + return { + instance: { + total: total, + inc: 0, + dec: 0 + } + }; + } + + @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 + }); + } +} + +export default new FederationChart(); |