From 1a2229f8865e67efe840b7eeed14e233a3730dcd Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 8 Apr 2019 14:29:17 +0900 Subject: [PATCH] Improve instance chart --- src/services/chart/charts/classes/instance.ts | 14 ++++++++++- src/services/chart/charts/schemas/instance.ts | 25 +++++++++++++++++++ src/services/note/create.ts | 2 +- src/services/note/delete.ts | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/services/chart/charts/classes/instance.ts b/src/services/chart/charts/classes/instance.ts index 974eac036..55db53457 100644 --- a/src/services/chart/charts/classes/instance.ts +++ b/src/services/chart/charts/classes/instance.ts @@ -4,6 +4,7 @@ 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'; +import { Note } from '../../../../models/entities/note'; type InstanceLog = SchemaType; @@ -107,12 +108,23 @@ export default class InstanceChart extends Chart { } @autobind - public async updateNote(host: string, isAdditional: boolean) { + public async updateNote(host: string, note: Note, isAdditional: boolean) { + const diffs = {} as any; + + if (note.replyId != null) { + diffs.reply = isAdditional ? 1 : -1; + } else if (note.renoteId != null) { + diffs.renote = isAdditional ? 1 : -1; + } else { + diffs.normal = isAdditional ? 1 : -1; + } + await this.inc({ notes: { total: isAdditional ? 1 : -1, inc: isAdditional ? 1 : 0, dec: isAdditional ? 0 : 1, + diffs: diffs } }, host); } diff --git a/src/services/chart/charts/schemas/instance.ts b/src/services/chart/charts/schemas/instance.ts index af46b3362..001f2428b 100644 --- a/src/services/chart/charts/schemas/instance.ts +++ b/src/services/chart/charts/schemas/instance.ts @@ -21,6 +21,7 @@ export const schema = { }, } }, + notes: { type: 'object' as 'object', properties: { @@ -36,8 +37,29 @@ export const schema = { type: 'number' as 'number', description: '減少した投稿数' }, + + diffs: { + type: 'object' as 'object', + properties: { + normal: { + type: 'number' as 'number', + description: '通常の投稿数の差分' + }, + + reply: { + type: 'number' as 'number', + description: 'リプライの投稿数の差分' + }, + + renote: { + type: 'number' as 'number', + description: 'Renoteの投稿数の差分' + }, + } + }, } }, + users: { type: 'object' as 'object', properties: { @@ -55,6 +77,7 @@ export const schema = { }, } }, + following: { type: 'object' as 'object', properties: { @@ -72,6 +95,7 @@ export const schema = { }, } }, + followers: { type: 'object' as 'object', properties: { @@ -89,6 +113,7 @@ export const schema = { }, } }, + drive: { type: 'object' as 'object', properties: { diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 305e173e1..05837a4da 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -207,7 +207,7 @@ export default async (user: User, data: Option, silent = false) => new Promise { Instances.increment({ id: i.id }, 'notesCount', 1); - instanceChart.updateNote(i.host, true); + instanceChart.updateNote(i.host, note, true); }); } diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index 7f04d12cd..c03c742ee 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -56,7 +56,7 @@ export default async function(user: User, note: Note, quiet = false) { if (Users.isRemoteUser(user)) { registerOrFetchInstanceDoc(user.host).then(i => { Instances.decrement({ id: i.id }, 'notesCount', 1); - instanceChart.updateNote(i.host, false); + instanceChart.updateNote(i.host, note, false); }); } }