mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-10 11:53:11 +02:00
Improve instance chart
This commit is contained in:
parent
1e166490d9
commit
1a2229f886
4 changed files with 40 additions and 3 deletions
|
@ -4,6 +4,7 @@ import { SchemaType } from '../../../../misc/schema';
|
||||||
import { DriveFiles, Followings, Users, Notes } from '../../../../models';
|
import { DriveFiles, Followings, Users, Notes } from '../../../../models';
|
||||||
import { DriveFile } from '../../../../models/entities/drive-file';
|
import { DriveFile } from '../../../../models/entities/drive-file';
|
||||||
import { name, schema } from '../schemas/instance';
|
import { name, schema } from '../schemas/instance';
|
||||||
|
import { Note } from '../../../../models/entities/note';
|
||||||
|
|
||||||
type InstanceLog = SchemaType<typeof schema>;
|
type InstanceLog = SchemaType<typeof schema>;
|
||||||
|
|
||||||
|
@ -107,12 +108,23 @@ export default class InstanceChart extends Chart<InstanceLog> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@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({
|
await this.inc({
|
||||||
notes: {
|
notes: {
|
||||||
total: isAdditional ? 1 : -1,
|
total: isAdditional ? 1 : -1,
|
||||||
inc: isAdditional ? 1 : 0,
|
inc: isAdditional ? 1 : 0,
|
||||||
dec: isAdditional ? 0 : 1,
|
dec: isAdditional ? 0 : 1,
|
||||||
|
diffs: diffs
|
||||||
}
|
}
|
||||||
}, host);
|
}, host);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ export const schema = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
notes: {
|
notes: {
|
||||||
type: 'object' as 'object',
|
type: 'object' as 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -36,8 +37,29 @@ export const schema = {
|
||||||
type: 'number' as 'number',
|
type: 'number' as 'number',
|
||||||
description: '減少した投稿数'
|
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: {
|
users: {
|
||||||
type: 'object' as 'object',
|
type: 'object' as 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -55,6 +77,7 @@ export const schema = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
following: {
|
following: {
|
||||||
type: 'object' as 'object',
|
type: 'object' as 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -72,6 +95,7 @@ export const schema = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
followers: {
|
followers: {
|
||||||
type: 'object' as 'object',
|
type: 'object' as 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -89,6 +113,7 @@ export const schema = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
drive: {
|
drive: {
|
||||||
type: 'object' as 'object',
|
type: 'object' as 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
|
|
@ -207,7 +207,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
|
||||||
if (Users.isRemoteUser(user)) {
|
if (Users.isRemoteUser(user)) {
|
||||||
registerOrFetchInstanceDoc(user.host).then(i => {
|
registerOrFetchInstanceDoc(user.host).then(i => {
|
||||||
Instances.increment({ id: i.id }, 'notesCount', 1);
|
Instances.increment({ id: i.id }, 'notesCount', 1);
|
||||||
instanceChart.updateNote(i.host, true);
|
instanceChart.updateNote(i.host, note, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ export default async function(user: User, note: Note, quiet = false) {
|
||||||
if (Users.isRemoteUser(user)) {
|
if (Users.isRemoteUser(user)) {
|
||||||
registerOrFetchInstanceDoc(user.host).then(i => {
|
registerOrFetchInstanceDoc(user.host).then(i => {
|
||||||
Instances.decrement({ id: i.id }, 'notesCount', 1);
|
Instances.decrement({ id: i.id }, 'notesCount', 1);
|
||||||
instanceChart.updateNote(i.host, false);
|
instanceChart.updateNote(i.host, note, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue