import autobind from 'autobind-decorator'; import Chart, { KVs } from '../core'; import { User } from '@/models/entities/user'; import { Notes } from '@/models/index'; import { Note } from '@/models/entities/note'; import { name, schema } from './entities/per-user-notes'; /** * ユーザーごとのノートに関するチャート */ // eslint-disable-next-line import/no-default-export export default class PerUserNotesChart extends Chart { constructor() { super(name, schema, true); } @autobind protected async tickMajor(group: string): Promise>> { const [count] = await Promise.all([ Notes.count({ userId: group }), ]); return { total: count, }; } @autobind protected async tickMinor(): Promise>> { return {}; } @autobind public async update(user: { id: User['id'] }, note: Note, isAdditional: boolean): Promise { await this.commit({ 'total': isAdditional ? 1 : -1, 'inc': isAdditional ? 1 : 0, 'dec': isAdditional ? 0 : 1, 'diffs.normal': note.replyId == null && note.renoteId == null ? (isAdditional ? 1 : -1) : 0, 'diffs.renote': note.renoteId != null ? (isAdditional ? 1 : -1) : 0, 'diffs.reply': note.replyId != null ? (isAdditional ? 1 : -1) : 0, 'diffs.withFile': note.fileIds.length > 0 ? (isAdditional ? 1 : -1) : 0, }, user.id); } }