summaryrefslogtreecommitdiff
path: root/packages/backend/src/services/chart/charts/notes.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-02-06 00:13:52 +0900
committerGitHub <noreply@github.com>2022-02-06 00:13:52 +0900
commitc1b264e4e9686804e1b8ea17ba39753c41bd205b (patch)
tree041e794b683cf986f98fcc04a3d5a50a8dcb7554 /packages/backend/src/services/chart/charts/notes.ts
parentenhance(client): improve chart rendering (diff)
downloadmisskey-c1b264e4e9686804e1b8ea17ba39753c41bd205b.tar.gz
misskey-c1b264e4e9686804e1b8ea17ba39753c41bd205b.tar.bz2
misskey-c1b264e4e9686804e1b8ea17ba39753c41bd205b.zip
Improve chart engine (#8253)
* wip * wip * wip * wip * wip * wip * wip * Update core.ts * wip * wip * #7361 * delete network chart * federationChart強化 apRequestChart追加 * tweak
Diffstat (limited to 'packages/backend/src/services/chart/charts/notes.ts')
-rw-r--r--packages/backend/src/services/chart/charts/notes.ts84
1 files changed, 13 insertions, 71 deletions
diff --git a/packages/backend/src/services/chart/charts/notes.ts b/packages/backend/src/services/chart/charts/notes.ts
index 86cda17225..4bbfa6704f 100644
--- a/packages/backend/src/services/chart/charts/notes.ts
+++ b/packages/backend/src/services/chart/charts/notes.ts
@@ -1,101 +1,43 @@
import autobind from 'autobind-decorator';
-import Chart, { Obj, DeepPartial } from '../core';
-import { SchemaType } from '@/misc/schema';
+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';
-type NotesLog = SchemaType<typeof schema>;
-
/**
* ノートに関するチャート
*/
// eslint-disable-next-line import/no-default-export
-export default class NotesChart extends Chart<NotesLog> {
+export default class NotesChart extends Chart<typeof schema> {
constructor() {
super(name, schema);
}
@autobind
- protected genNewLog(latest: NotesLog): DeepPartial<NotesLog> {
- return {
- local: {
- total: latest.local.total,
- },
- remote: {
- total: latest.remote.total,
- },
- };
- }
-
- @autobind
- protected aggregate(logs: NotesLog[]): NotesLog {
- return {
- local: {
- total: logs[0].local.total,
- inc: logs.reduce((a, b) => a + b.local.inc, 0),
- dec: logs.reduce((a, b) => a + b.local.dec, 0),
- diffs: {
- reply: logs.reduce((a, b) => a + b.local.diffs.reply, 0),
- renote: logs.reduce((a, b) => a + b.local.diffs.renote, 0),
- normal: logs.reduce((a, b) => a + b.local.diffs.normal, 0),
- },
- },
- remote: {
- total: logs[0].remote.total,
- inc: logs.reduce((a, b) => a + b.remote.inc, 0),
- dec: logs.reduce((a, b) => a + b.remote.dec, 0),
- diffs: {
- reply: logs.reduce((a, b) => a + b.remote.diffs.reply, 0),
- renote: logs.reduce((a, b) => a + b.remote.diffs.renote, 0),
- normal: logs.reduce((a, b) => a + b.remote.diffs.normal, 0),
- },
- },
- };
- }
-
- @autobind
- protected async fetchActual(): Promise<DeepPartial<NotesLog>> {
+ 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,
- },
+ 'local.total': localCount,
+ 'remote.total': remoteCount,
};
}
@autobind
public async update(note: Note, isAdditional: boolean): Promise<void> {
- const update: Obj = {
- diffs: {},
- };
-
- update.total = isAdditional ? 1 : -1;
-
- if (isAdditional) {
- update.inc = 1;
- } else {
- update.dec = 1;
- }
-
- if (note.replyId != null) {
- update.diffs.reply = isAdditional ? 1 : -1;
- } else if (note.renoteId != null) {
- update.diffs.renote = isAdditional ? 1 : -1;
- } else {
- update.diffs.normal = isAdditional ? 1 : -1;
- }
+ const prefix = note.userHost === null ? 'local' : 'remote';
- await this.inc({
- [note.userHost === null ? 'local' : 'remote']: update,
+ 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,
});
}
}