1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-03 17:28:28 +09:00
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;
/**
*
*
*/
diff: number;
};
@ -30,7 +30,7 @@ export interface IChart {
total: number;
/**
*
*
*/
diff: number;
};
@ -43,19 +43,24 @@ export interface IChart {
*/
total: number;
/**
* 稿
*/
diff: number;
diffs: {
/**
* 稿
* 稿
*/
normal: number;
/**
* 稿
* 稿
*/
reply: number;
/**
* Renoteの投稿数の前日比
* Renoteの投稿数の前日比
*/
renote: number;
};
@ -67,19 +72,24 @@ export interface IChart {
*/
total: number;
/**
* 稿
*/
diff: number;
diffs: {
/**
* 稿
* 稿
*/
normal: number;
/**
* 稿
* 稿
*/
reply: number;
/**
* Renoteの投稿数の前日比
* Renoteの投稿数の前日比
*/
renote: number;
};

View File

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