mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2025-03-04 07:18:50 -07:00
* wip * wip * wip * wip * wip * wip * wip * Update core.ts * wip * wip * #7361 * delete network chart * federationChart強化 apRequestChart追加 * tweak
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import autobind from 'autobind-decorator';
|
|
import Chart, { KVs } from '../core';
|
|
import { Notes } from '@/models/index';
|
|
import { Not, IsNull } from 'typeorm';
|
|
import { Note } from '@/models/entities/note';
|
|
import { name, schema } from './entities/notes';
|
|
|
|
/**
|
|
* ノートに関するチャート
|
|
*/
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default class NotesChart extends Chart<typeof schema> {
|
|
constructor() {
|
|
super(name, schema);
|
|
}
|
|
|
|
@autobind
|
|
protected async queryCurrentState(): Promise<Partial<KVs<typeof schema>>> {
|
|
const [localCount, remoteCount] = await Promise.all([
|
|
Notes.count({ userHost: null }),
|
|
Notes.count({ userHost: Not(IsNull()) }),
|
|
]);
|
|
|
|
return {
|
|
'local.total': localCount,
|
|
'remote.total': remoteCount,
|
|
};
|
|
}
|
|
|
|
@autobind
|
|
public async update(note: Note, isAdditional: boolean): Promise<void> {
|
|
const prefix = note.userHost === null ? 'local' : 'remote';
|
|
|
|
await this.commit({
|
|
[`${prefix}.total`]: isAdditional ? 1 : -1,
|
|
[`${prefix}.inc`]: isAdditional ? 1 : 0,
|
|
[`${prefix}.dec`]: isAdditional ? 0 : 1,
|
|
[`${prefix}.diffs.normal`]: note.replyId == null && note.renoteId == null ? (isAdditional ? 1 : -1) : 0,
|
|
[`${prefix}.diffs.renote`]: note.renoteId != null ? (isAdditional ? 1 : -1) : 0,
|
|
[`${prefix}.diffs.reply`]: note.replyId != null ? (isAdditional ? 1 : -1) : 0,
|
|
});
|
|
}
|
|
}
|