Improve instance chart

This commit is contained in:
syuilo 2019-04-08 14:29:17 +09:00
parent 1e166490d9
commit 1a2229f886
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
4 changed files with 40 additions and 3 deletions

View file

@ -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<typeof schema>;
@ -107,12 +108,23 @@ export default class InstanceChart extends Chart<InstanceLog> {
}
@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);
}

View file

@ -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: {

View file

@ -207,7 +207,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
if (Users.isRemoteUser(user)) {
registerOrFetchInstanceDoc(user.host).then(i => {
Instances.increment({ id: i.id }, 'notesCount', 1);
instanceChart.updateNote(i.host, true);
instanceChart.updateNote(i.host, note, true);
});
}

View file

@ -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);
});
}
}