This commit is contained in:
syuilo 2018-08-18 23:23:55 +09:00
parent c3cd0451ad
commit ef79903811
2 changed files with 34 additions and 12 deletions

View file

@ -18,7 +18,7 @@ export interface IChart {
total: number; total: number;
/** /**
* *
*/ */
diff: number; diff: number;
}; };
@ -30,7 +30,7 @@ export interface IChart {
total: number; total: number;
/** /**
* *
*/ */
diff: number; diff: number;
}; };
@ -43,19 +43,24 @@ export interface IChart {
*/ */
total: number; total: number;
/**
* 稿
*/
diff: number;
diffs: { diffs: {
/** /**
* 稿 * 稿
*/ */
normal: number; normal: number;
/** /**
* 稿 * 稿
*/ */
reply: number; reply: number;
/** /**
* Renoteの投稿数の前日比 * Renoteの投稿数の前日比
*/ */
renote: number; renote: number;
}; };
@ -67,19 +72,24 @@ export interface IChart {
*/ */
total: number; total: number;
/**
* 稿
*/
diff: number;
diffs: { diffs: {
/** /**
* 稿 * 稿
*/ */
normal: number; normal: number;
/** /**
* 稿 * 稿
*/ */
reply: number; reply: number;
/** /**
* Renoteの投稿数の前日比 * Renoteの投稿数の前日比
*/ */
renote: number; renote: number;
}; };

View file

@ -2,6 +2,8 @@ import { INote } from '../models/note';
import Chart, { IChart } from '../models/chart'; import Chart, { IChart } from '../models/chart';
import { isLocalUser, IUser } from '../models/user'; import { isLocalUser, IUser } from '../models/user';
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
async function getTodayStats(): Promise<IChart> { async function getTodayStats(): Promise<IChart> {
const now = new Date(); const now = new Date();
const y = now.getFullYear(); const y = now.getFullYear();
@ -30,7 +32,7 @@ async function getTodayStats(): Promise<IChart> {
// * Misskeyインスタンスを建てて初めてのチャート更新時など // * Misskeyインスタンスを建てて初めてのチャート更新時など
if (mostRecentStats == null) { if (mostRecentStats == null) {
// 空の統計を作成 // 空の統計を作成
const stats = await Chart.insert({ const chart: Omit<IChart, '_id'> = {
date: today, date: today,
users: { users: {
local: { local: {
@ -45,6 +47,7 @@ async function getTodayStats(): Promise<IChart> {
notes: { notes: {
local: { local: {
total: 0, total: 0,
diff: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -53,6 +56,7 @@ async function getTodayStats(): Promise<IChart> {
}, },
remote: { remote: {
total: 0, total: 0,
diff: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -60,12 +64,14 @@ async function getTodayStats(): Promise<IChart> {
} }
} }
} }
}); };
const stats = await Chart.insert(chart);
return stats; return stats;
} else { } else {
// 今日の統計を初期挿入 // 今日の統計を初期挿入
const stats = await Chart.insert({ const chart: Omit<IChart, '_id'> = {
date: today, date: today,
users: { users: {
local: { local: {
@ -80,6 +86,7 @@ async function getTodayStats(): Promise<IChart> {
notes: { notes: {
local: { local: {
total: mostRecentStats.notes.local.total, total: mostRecentStats.notes.local.total,
diff: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -88,6 +95,7 @@ async function getTodayStats(): Promise<IChart> {
}, },
remote: { remote: {
total: mostRecentStats.notes.remote.total, total: mostRecentStats.notes.remote.total,
diff: 0,
diffs: { diffs: {
normal: 0, normal: 0,
reply: 0, reply: 0,
@ -95,7 +103,9 @@ async function getTodayStats(): Promise<IChart> {
} }
} }
} }
}); };
const stats = await Chart.insert(chart);
return stats; return stats;
} }
@ -137,6 +147,7 @@ export async function updateNoteStats(note: INote, isAdditional: boolean) {
if (isLocalUser(note._user)) { if (isLocalUser(note._user)) {
inc['notes.local.total'] = val; inc['notes.local.total'] = val;
inc['notes.local.diff'] = val;
if (note.replyId != null) { if (note.replyId != null) {
inc['notes.local.diffs.reply'] = val; inc['notes.local.diffs.reply'] = val;
@ -147,6 +158,7 @@ export async function updateNoteStats(note: INote, isAdditional: boolean) {
} }
} else { } else {
inc['notes.remote.total'] = val; inc['notes.remote.total'] = val;
inc['notes.remote.diff'] = val;
if (note.replyId != null) { if (note.replyId != null) {
inc['notes.remote.diffs.reply'] = val; inc['notes.remote.diffs.reply'] = val;