リファクタリング syuilo#4587 (#4766)
This commit is contained in:
@@ -56,20 +56,12 @@ function cpuUsage() {
|
|||||||
|
|
||||||
// MEMORY(excl buffer + cache) STAT
|
// MEMORY(excl buffer + cache) STAT
|
||||||
async function usedMem() {
|
async function usedMem() {
|
||||||
try {
|
|
||||||
const data = await sysUtils.mem();
|
const data = await sysUtils.mem();
|
||||||
return data.active;
|
return data.active;
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOTAL MEMORY STAT
|
// TOTAL MEMORY STAT
|
||||||
async function totalMem() {
|
async function totalMem() {
|
||||||
try {
|
|
||||||
const data = await sysUtils.mem();
|
const data = await sysUtils.mem();
|
||||||
return data.total;
|
return data.total;
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
export interface Maybe<T> {
|
export interface IMaybe<T> {
|
||||||
isJust(): this is Just<T>;
|
isJust(): this is IJust<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Just<T> = Maybe<T> & {
|
export interface IJust<T> extends IMaybe<T> {
|
||||||
get(): T
|
get(): T;
|
||||||
};
|
}
|
||||||
|
|
||||||
export function just<T>(value: T): Just<T> {
|
export function just<T>(value: T): IJust<T> {
|
||||||
return {
|
return {
|
||||||
isJust: () => true,
|
isJust: () => true,
|
||||||
get: () => value
|
get: () => value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function nothing<T>(): Maybe<T> {
|
export function nothing<T>(): IMaybe<T> {
|
||||||
return {
|
return {
|
||||||
isJust: () => false,
|
isJust: () => false,
|
||||||
};
|
};
|
||||||
|
@@ -16,10 +16,9 @@ export async function deleteDriveFiles(job: Bull.Job, done: any): Promise<void>
|
|||||||
});
|
});
|
||||||
|
|
||||||
let deletedCount = 0;
|
let deletedCount = 0;
|
||||||
let ended = false;
|
|
||||||
let cursor: any = null;
|
let cursor: any = null;
|
||||||
|
|
||||||
while (!ended) {
|
while (true) {
|
||||||
const files = await DriveFile.find({
|
const files = await DriveFile.find({
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
...(cursor ? { _id: { $gt: cursor } } : {})
|
...(cursor ? { _id: { $gt: cursor } } : {})
|
||||||
@@ -31,7 +30,6 @@ export async function deleteDriveFiles(job: Bull.Job, done: any): Promise<void>
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
ended = true;
|
|
||||||
job.progress(100);
|
job.progress(100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -32,10 +32,9 @@ export async function exportBlocking(job: Bull.Job, done: any): Promise<void> {
|
|||||||
const stream = fs.createWriteStream(path, { flags: 'a' });
|
const stream = fs.createWriteStream(path, { flags: 'a' });
|
||||||
|
|
||||||
let exportedCount = 0;
|
let exportedCount = 0;
|
||||||
let ended = false;
|
|
||||||
let cursor: any = null;
|
let cursor: any = null;
|
||||||
|
|
||||||
while (!ended) {
|
while (true) {
|
||||||
const blockings = await Blocking.find({
|
const blockings = await Blocking.find({
|
||||||
blockerId: user._id,
|
blockerId: user._id,
|
||||||
...(cursor ? { _id: { $gt: cursor } } : {})
|
...(cursor ? { _id: { $gt: cursor } } : {})
|
||||||
@@ -47,7 +46,6 @@ export async function exportBlocking(job: Bull.Job, done: any): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (blockings.length === 0) {
|
if (blockings.length === 0) {
|
||||||
ended = true;
|
|
||||||
job.progress(100);
|
job.progress(100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -32,10 +32,9 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> {
|
|||||||
const stream = fs.createWriteStream(path, { flags: 'a' });
|
const stream = fs.createWriteStream(path, { flags: 'a' });
|
||||||
|
|
||||||
let exportedCount = 0;
|
let exportedCount = 0;
|
||||||
let ended = false;
|
|
||||||
let cursor: any = null;
|
let cursor: any = null;
|
||||||
|
|
||||||
while (!ended) {
|
while (true) {
|
||||||
const followings = await Following.find({
|
const followings = await Following.find({
|
||||||
followerId: user._id,
|
followerId: user._id,
|
||||||
...(cursor ? { _id: { $gt: cursor } } : {})
|
...(cursor ? { _id: { $gt: cursor } } : {})
|
||||||
@@ -47,7 +46,6 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (followings.length === 0) {
|
if (followings.length === 0) {
|
||||||
ended = true;
|
|
||||||
job.progress(100);
|
job.progress(100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -32,10 +32,9 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> {
|
|||||||
const stream = fs.createWriteStream(path, { flags: 'a' });
|
const stream = fs.createWriteStream(path, { flags: 'a' });
|
||||||
|
|
||||||
let exportedCount = 0;
|
let exportedCount = 0;
|
||||||
let ended = false;
|
|
||||||
let cursor: any = null;
|
let cursor: any = null;
|
||||||
|
|
||||||
while (!ended) {
|
while (true) {
|
||||||
const mutes = await Mute.find({
|
const mutes = await Mute.find({
|
||||||
muterId: user._id,
|
muterId: user._id,
|
||||||
...(cursor ? { _id: { $gt: cursor } } : {})
|
...(cursor ? { _id: { $gt: cursor } } : {})
|
||||||
@@ -47,7 +46,6 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (mutes.length === 0) {
|
if (mutes.length === 0) {
|
||||||
ended = true;
|
|
||||||
job.progress(100);
|
job.progress(100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -42,10 +42,9 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let exportedNotesCount = 0;
|
let exportedNotesCount = 0;
|
||||||
let ended = false;
|
|
||||||
let cursor: any = null;
|
let cursor: any = null;
|
||||||
|
|
||||||
while (!ended) {
|
while (true) {
|
||||||
const notes = await Note.find({
|
const notes = await Note.find({
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
...(cursor ? { _id: { $gt: cursor } } : {})
|
...(cursor ? { _id: { $gt: cursor } } : {})
|
||||||
@@ -57,7 +56,6 @@ export async function exportNotes(job: Bull.Job, done: any): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (notes.length === 0) {
|
if (notes.length === 0) {
|
||||||
ended = true;
|
|
||||||
job.progress(100);
|
job.progress(100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,7 @@ export default async (user: ILocalUser, url: string, object: any) => {
|
|||||||
const addr = await resolveAddr(hostname);
|
const addr = await resolveAddr(hostname);
|
||||||
if (!addr) return;
|
if (!addr) return;
|
||||||
|
|
||||||
const _ = new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const req = request({
|
const req = request({
|
||||||
protocol,
|
protocol,
|
||||||
hostname: addr,
|
hostname: addr,
|
||||||
@@ -82,8 +82,6 @@ export default async (user: ILocalUser, url: string, object: any) => {
|
|||||||
req.end(data);
|
req.end(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
await _;
|
|
||||||
|
|
||||||
//#region Log
|
//#region Log
|
||||||
publishApLogStream({
|
publishApLogStream({
|
||||||
direction: 'out',
|
direction: 'out',
|
||||||
|
Reference in New Issue
Block a user