forked from FoundKeyGang/FoundKey
リファクタリング (#4587)
* Use I cap * Avoid _ * Use default value instead of optional boolean * Bye useless variable * Bye verbose try-catch
This commit is contained in:
parent
97bff010a8
commit
054220db70
8 changed files with 17 additions and 37 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
export interface Maybe<T> {
|
||||
isJust(): this is Just<T>;
|
||||
export interface IMaybe<T> {
|
||||
isJust(): this is IJust<T>;
|
||||
}
|
||||
|
||||
export type Just<T> = Maybe<T> & {
|
||||
get(): T
|
||||
};
|
||||
export interface IJust<T> extends IMaybe<T> {
|
||||
get(): T;
|
||||
}
|
||||
|
||||
export function just<T>(value: T): Just<T> {
|
||||
export function just<T>(value: T): IJust<T> {
|
||||
return {
|
||||
isJust: () => true,
|
||||
get: () => value
|
||||
};
|
||||
}
|
||||
|
||||
export function nothing<T>(): Maybe<T> {
|
||||
export function nothing<T>(): IMaybe<T> {
|
||||
return {
|
||||
isJust: () => false,
|
||||
};
|
||||
|
|
|
@ -17,10 +17,9 @@ export async function deleteDriveFiles(job: Bull.Job, done: any): Promise<void>
|
|||
}
|
||||
|
||||
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<void>
|
|||
});
|
||||
|
||||
if (files.length === 0) {
|
||||
ended = true;
|
||||
job.progress(100);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,9 @@ export async function exportBlocking(job: Bull.Job, done: any): Promise<void> {
|
|||
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<void> {
|
|||
});
|
||||
|
||||
if (blockings.length === 0) {
|
||||
ended = true;
|
||||
job.progress(100);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,9 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> {
|
|||
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<void> {
|
|||
});
|
||||
|
||||
if (followings.length === 0) {
|
||||
ended = true;
|
||||
job.progress(100);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,9 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> {
|
|||
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<void> {
|
|||
});
|
||||
|
||||
if (mutes.length === 0) {
|
||||
ended = true;
|
||||
job.progress(100);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -46,10 +46,9 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
|
|||
});
|
||||
|
||||
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<void> {
|
|||
});
|
||||
|
||||
if (notes.length === 0) {
|
||||
ended = true;
|
||||
job.progress(100);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue