summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-08-18 23:23:55 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-08-18 23:23:55 +0900
commitef799038110f5a3a40752b5e80e0f146fbe126f4 (patch)
treef9bfba75dcb1632982185490154fe6b3ddf74fef /src
parentwip (diff)
downloadsharkey-ef799038110f5a3a40752b5e80e0f146fbe126f4.tar.gz
sharkey-ef799038110f5a3a40752b5e80e0f146fbe126f4.tar.bz2
sharkey-ef799038110f5a3a40752b5e80e0f146fbe126f4.zip
wip
Diffstat (limited to 'src')
-rw-r--r--src/models/chart.ts26
-rw-r--r--src/services/update-chart.ts20
2 files changed, 34 insertions, 12 deletions
diff --git a/src/models/chart.ts b/src/models/chart.ts
index 2063408d81..e7e85c9481 100644
--- a/src/models/chart.ts
+++ b/src/models/chart.ts
@@ -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;
};
diff --git a/src/services/update-chart.ts b/src/services/update-chart.ts
index f7997cb774..bd4fcbbeda 100644
--- a/src/services/update-chart.ts
+++ b/src/services/update-chart.ts
@@ -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;