From 054220db704a48b5db3066d660a48c09356e916c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sun, 14 Apr 2019 17:18:17 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF?= =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=B0=20(#4587)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use I cap * Avoid _ * Use default value instead of optional boolean * Bye useless variable * Bye verbose try-catch --- src/daemons/server-stats.ts | 16 ++++------------ src/prelude/maybe.ts | 14 +++++++------- src/queue/processors/db/delete-drive-files.ts | 4 +--- src/queue/processors/db/export-blocking.ts | 4 +--- src/queue/processors/db/export-following.ts | 4 +--- src/queue/processors/db/export-mute.ts | 4 +--- src/queue/processors/db/export-notes.ts | 4 +--- src/remote/activitypub/request.ts | 4 +--- 8 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/daemons/server-stats.ts b/src/daemons/server-stats.ts index b82f42177..ee62c32d7 100644 --- a/src/daemons/server-stats.ts +++ b/src/daemons/server-stats.ts @@ -56,20 +56,12 @@ function cpuUsage() { // MEMORY(excl buffer + cache) STAT async function usedMem() { - try { - const data = await sysUtils.mem(); - return data.active; - } catch (error) { - throw error; - } + const data = await sysUtils.mem(); + return data.active; } // TOTAL MEMORY STAT async function totalMem() { - try { - const data = await sysUtils.mem(); - return data.total; - } catch (error) { - throw error; - } + const data = await sysUtils.mem(); + return data.total; } diff --git a/src/prelude/maybe.ts b/src/prelude/maybe.ts index f9ac95c0b..0b4b543ca 100644 --- a/src/prelude/maybe.ts +++ b/src/prelude/maybe.ts @@ -1,19 +1,19 @@ -export interface Maybe { - isJust(): this is Just; +export interface IMaybe { + isJust(): this is IJust; } -export type Just = Maybe & { - get(): T -}; +export interface IJust extends IMaybe { + get(): T; +} -export function just(value: T): Just { +export function just(value: T): IJust { return { isJust: () => true, get: () => value }; } -export function nothing(): Maybe { +export function nothing(): IMaybe { return { isJust: () => false, }; diff --git a/src/queue/processors/db/delete-drive-files.ts b/src/queue/processors/db/delete-drive-files.ts index 491734acc..4e4eab86b 100644 --- a/src/queue/processors/db/delete-drive-files.ts +++ b/src/queue/processors/db/delete-drive-files.ts @@ -17,10 +17,9 @@ export async function deleteDriveFiles(job: Bull.Job, done: any): Promise } let deletedCount = 0; - let ended = false; let cursor: any = null; - while (!ended) { + while (true) { const files = await DriveFiles.find({ where: { userId: user.id, @@ -33,7 +32,6 @@ export async function deleteDriveFiles(job: Bull.Job, done: any): Promise }); if (files.length === 0) { - ended = true; job.progress(100); break; } diff --git a/src/queue/processors/db/export-blocking.ts b/src/queue/processors/db/export-blocking.ts index 44025ec96..c4b8c9438 100644 --- a/src/queue/processors/db/export-blocking.ts +++ b/src/queue/processors/db/export-blocking.ts @@ -33,10 +33,9 @@ export async function exportBlocking(job: Bull.Job, done: any): Promise { const stream = fs.createWriteStream(path, { flags: 'a' }); let exportedCount = 0; - let ended = false; let cursor: any = null; - while (!ended) { + while (true) { const blockings = await Blockings.find({ where: { blockerId: user.id, @@ -49,7 +48,6 @@ export async function exportBlocking(job: Bull.Job, done: any): Promise { }); if (blockings.length === 0) { - ended = true; job.progress(100); break; } diff --git a/src/queue/processors/db/export-following.ts b/src/queue/processors/db/export-following.ts index 81dcf8f93..9fab5bb21 100644 --- a/src/queue/processors/db/export-following.ts +++ b/src/queue/processors/db/export-following.ts @@ -33,10 +33,9 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise { const stream = fs.createWriteStream(path, { flags: 'a' }); let exportedCount = 0; - let ended = false; let cursor: any = null; - while (!ended) { + while (true) { const followings = await Followings.find({ where: { followerId: user.id, @@ -49,7 +48,6 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise { }); if (followings.length === 0) { - ended = true; job.progress(100); break; } diff --git a/src/queue/processors/db/export-mute.ts b/src/queue/processors/db/export-mute.ts index f810b6ee8..b957b48b2 100644 --- a/src/queue/processors/db/export-mute.ts +++ b/src/queue/processors/db/export-mute.ts @@ -33,10 +33,9 @@ export async function exportMute(job: Bull.Job, done: any): Promise { const stream = fs.createWriteStream(path, { flags: 'a' }); let exportedCount = 0; - let ended = false; let cursor: any = null; - while (!ended) { + while (true) { const mutes = await Mutings.find({ where: { muterId: user.id, @@ -49,7 +48,6 @@ export async function exportMute(job: Bull.Job, done: any): Promise { }); if (mutes.length === 0) { - ended = true; job.progress(100); break; } diff --git a/src/queue/processors/db/export-notes.ts b/src/queue/processors/db/export-notes.ts index eaa5caf63..d03a216a5 100644 --- a/src/queue/processors/db/export-notes.ts +++ b/src/queue/processors/db/export-notes.ts @@ -46,10 +46,9 @@ export async function exportNotes(job: Bull.Job, done: any): Promise { }); let exportedNotesCount = 0; - let ended = false; let cursor: any = null; - while (!ended) { + while (true) { const notes = await Notes.find({ where: { userId: user.id, @@ -62,7 +61,6 @@ export async function exportNotes(job: Bull.Job, done: any): Promise { }); if (notes.length === 0) { - ended = true; job.progress(100); break; } diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index 7dc48c15e..897dd9aca 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -41,7 +41,7 @@ export default async (user: ILocalUser, url: string, object: any) => { userId: user.id }).then(ensure); - const _ = new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { const req = request({ protocol, hostname: addr, @@ -88,8 +88,6 @@ export default async (user: ILocalUser, url: string, object: any) => { req.end(data); }); - await _; - //#region Log publishApLogStream({ direction: 'out',