summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-08-19 03:06:23 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-08-19 03:06:23 +0900
commit667b18fe242b603407ea79dcf730f79245947609 (patch)
tree463b09cb9fa8a6b6502b89dcdfe84a32e8db5d7d /src/services
parentMerge pull request #2311 from acid-chicken/patch-autogen (diff)
downloadsharkey-667b18fe242b603407ea79dcf730f79245947609.tar.gz
sharkey-667b18fe242b603407ea79dcf730f79245947609.tar.bz2
sharkey-667b18fe242b603407ea79dcf730f79245947609.zip
Refactoring
Diffstat (limited to 'src/services')
-rw-r--r--src/services/update-chart.ts72
1 files changed, 24 insertions, 48 deletions
diff --git a/src/services/update-chart.ts b/src/services/update-chart.ts
index 7998baca9d..6b69adbdc3 100644
--- a/src/services/update-chart.ts
+++ b/src/services/update-chart.ts
@@ -33,7 +33,7 @@ async function getTodayStats(): Promise<IStats> {
// * Misskeyインスタンスを建てて初めてのチャート更新時など
if (mostRecentStats == null) {
// 空の統計を作成
- const chart: Omit<IStats, '_id'> = {
+ const data: Omit<IStats, '_id'> = {
date: today,
users: {
local: {
@@ -81,12 +81,12 @@ async function getTodayStats(): Promise<IStats> {
}
};
- const stats = await Stats.insert(chart);
+ const stats = await Stats.insert(data);
return stats;
} else {
// 今日の統計を初期挿入
- const chart: Omit<IStats, '_id'> = {
+ const data: Omit<IStats, '_id'> = {
date: today,
users: {
local: {
@@ -134,7 +134,7 @@ async function getTodayStats(): Promise<IStats> {
}
};
- const stats = await Stats.insert(chart);
+ const stats = await Stats.insert(data);
return stats;
}
@@ -154,70 +154,46 @@ async function update(inc: any) {
}
export async function updateUserStats(user: IUser, isAdditional: boolean) {
- const inc = {} as any;
-
const amount = isAdditional ? 1 : -1;
+ const origin = isLocalUser(user) ? 'local' : 'remote';
- if (isLocalUser(user)) {
- inc['users.local.total'] = amount;
- inc['users.local.diff'] = amount;
- } else {
- inc['users.remote.total'] = amount;
- inc['users.remote.diff'] = amount;
- }
+ const inc = {} as any;
+ inc[`users.${origin}.total`] = amount;
+ inc[`users.${origin}.diff`] = amount;
await update(inc);
}
export async function updateNoteStats(note: INote, isAdditional: boolean) {
- const inc = {} as any;
-
const amount = isAdditional ? 1 : -1;
+ const origin = isLocalUser(note._user) ? 'local' : 'remote';
- if (isLocalUser(note._user)) {
- inc['notes.local.total'] = amount;
- inc['notes.local.diff'] = amount;
+ const inc = {} as any;
- if (note.replyId != null) {
- inc['notes.local.diffs.reply'] = amount;
- } else if (note.renoteId != null) {
- inc['notes.local.diffs.renote'] = amount;
- } else {
- inc['notes.local.diffs.normal'] = amount;
- }
- } else {
- inc['notes.remote.total'] = amount;
- inc['notes.remote.diff'] = amount;
+ inc[`notes.${origin}.total`] = amount;
+ inc[`notes.${origin}.diff`] = amount;
- if (note.replyId != null) {
- inc['notes.remote.diffs.reply'] = amount;
- } else if (note.renoteId != null) {
- inc['notes.remote.diffs.renote'] = amount;
- } else {
- inc['notes.remote.diffs.normal'] = amount;
- }
+ if (note.replyId != null) {
+ inc[`notes.${origin}.diffs.reply`] = amount;
+ } else if (note.renoteId != null) {
+ inc[`notes.${origin}.diffs.renote`] = amount;
+ } else {
+ inc[`notes.${origin}.diffs.normal`] = amount;
}
await update(inc);
}
export async function updateDriveStats(file: IDriveFile, isAdditional: boolean) {
- const inc = {} as any;
-
const amount = isAdditional ? 1 : -1;
const size = isAdditional ? file.length : -file.length;
+ const origin = isLocalUser(file.metadata._user) ? 'local' : 'remote';
- if (isLocalUser(file.metadata._user)) {
- inc['drive.local.totalCount'] = amount;
- inc['drive.local.diffCount'] = amount;
- inc['drive.local.totalSize'] = size;
- inc['drive.local.diffSize'] = size;
- } else {
- inc['drive.remote.total'] = amount;
- inc['drive.remote.diff'] = amount;
- inc['drive.remote.totalSize'] = size;
- inc['drive.remote.diffSize'] = size;
- }
+ const inc = {} as any;
+ inc[`drive.${origin}.totalCount`] = amount;
+ inc[`drive.${origin}.diffCount`] = amount;
+ inc[`drive.${origin}.totalSize`] = size;
+ inc[`drive.${origin}.diffSize`] = size;
await update(inc);
}